繁体   English   中英

通过自连接同一个表进行计数,其中一个字段为空但另一个字段具有值

[英]Count by Self Joining same table where one field is empty but another has value

我有一个包含两组 GPS 坐标的表格,一组由客户提供,另一组由我们的现场设备捕获。

表名为customer,字段名如下:

ID

纬度 [来自客户的数据]

经度 [来自客户的数据]

GPSLatitude [来自现场设备的数据]

GPSLongitude [来自现场设备的数据]

  1. 我想计算纬度和经度均为空白或包含值 = 0 的所有此类行。
  2. 然后统计所有 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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM