select count(type) from (
selectdistinct ID01 as type from QRQC_TRACK_REPORT where type='APW'and ZT is null or ZT='唤醒' )本来是这么写的 但是表里没有 'APW' 这个数据 还是能查到有一条(ZT为关闭和冻结的不统计或者只统计ZT为唤醒和空的)
收起
你and 和 or 在一层,就都变成or了,要加括号
select distinct ID01 as type from QRQC_TRACK_REPORT where type='APW' and (ZT is null or ZT='唤醒')
count里面是可以套distinct 的
select count(distinct ID01) from QRQC_TRACK_REPORT where type='APW' and (ZT is null or ZT='唤醒')
报告相同问题?