我正在尝试处理COUNT CASE WHEN
语句。
我想计算8-17小时之间的总和,以及这些时间以外的其他总和。我在下面的查询总是返回总计。
SELECT DISTINCT tSource,
COUNT(case when (tTime between '08:00:00' and '17:00:00') then 1 else 0 end) as tIN,
COUNT(case when (tTime not between '08:00:00' and '17:00:00') then 1 else 0 end) as tOUT
FROM @tTable
tTotal tIN tOUT
28 13 15
4167 1167 3000