sql - 通过自连接同一表进行计数,其中一个字段为空,但另一个字段具有值
问题描述
我有一张表,其中包含两组 GPS 坐标,一组由客户提供,另一组由我们的现场设备捕获。
表名为customer,字段名如下:
ID
纬度 [来自客户的数据]
经度 [来自客户的数据]
GPSLatitude [来自现场设备的数据]
GPSLongitude [来自现场设备的数据]
- 我想计算纬度和经度都是空白或包含值=0的所有此类行。
- 然后计算所有 GPSLatitude、GPSLongitude,其 ID 等于在 #1 中计数且不为空或不包含 value=0 的那些记录
解决方案
我认为你想要条件聚合:
select count(*) cnt1,
sum(case when gpslatitude <> 0 and gpslongitude <> 0 then 1 else 0 end) cnt2
from customer
where (latitude is null or latitude = 0)
and (longitude is null or longitude = 0)
查询过滤客户经度和纬度null
等于或等于0
。cnt1
为您提供此类记录的计数。然后cnt2
计算结果集中有多少条记录既不具有null
也不具有设备坐标0
。
推荐阅读
- mysql - 检查 MySQL 版本时访问被拒绝
- r - R中的引导程序无法正确再现样本
- python - 如何使用 Paramiko exec_command 获取每个依赖的命令执行输出
- javascript - 如何通过类名修改 HTML 标签内的值
- c - C 程序在接受 scanf() 输入之前终止
- python - 尝试基本 tensorflow 代码时出现运行时错误
- coldfusion - 在 ColdFusion 2018 中启用空支持问题
- python - 连接到 AWS Aurora 集群时偶尔出现“名称解析暂时失败”
- php - 使用php在数组中获取特定列值的问题
- php - 如何使用我的 secugen 扫描仪指纹结果对 *.WSQ 文件进行身份验证?