通过自连接计数相同 table 其中一个字段为空但另一个字段具有值
Count by Self Joining same table where one field is empty but another has value
我有一个 table,其中包含两组 GPS 坐标,一组由客户提供,另一组由我们的现场设备捕获。
table的名字是customer,字段名如下:
ID
Latitude [来自客户的数据]
经度[来自客户的数据]
GPSLatitude [来自现场设备的数据]
GPSLongitude [来自现场设备的数据]
- 我想计算所有这样的行,其中 纬度和
经度为空白或包含 value=0.
- 然后统计所有的GPSLatitude,GPSLongitude,其ID等于在#1中统计的那些记录并且不为空或不包含值=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
.
我有一个 table,其中包含两组 GPS 坐标,一组由客户提供,另一组由我们的现场设备捕获。
table的名字是customer,字段名如下:
ID
Latitude [来自客户的数据]
经度[来自客户的数据]
GPSLatitude [来自现场设备的数据]
GPSLongitude [来自现场设备的数据]
- 我想计算所有这样的行,其中 纬度和 经度为空白或包含 value=0.
- 然后统计所有的GPSLatitude,GPSLongitude,其ID等于在#1中统计的那些记录并且不为空或不包含值=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
.