[英]Count by Self Joining same table where one field is empty but another has value
我有一个包含两组 GPS 坐标的表格,一组由客户提供,另一组由我们的现场设备捕获。
表名为customer,字段名如下:
ID
纬度 [来自客户的数据]
经度 [来自客户的数据]
GPSLatitude [来自现场设备的数据]
GPSLongitude [来自现场设备的数据]
我想你想要条件聚合:
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
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.