SELECT 单位,年级,班级,报告类型,报告人,报告日期,
sum(case when 处置情况 is not null then 1 else 0 end) + sum(case when 考勤原因 is not null then 1 else 0 end) as 异常学生数
-- 异常学生+缺勤学生
FROM dbo.晨午检
-- where 缺勤原因 is not NULL and 处置情况 is not NULL
group by 单位,年级,班级,报告类型,报告人,报告日期
SELECT 单位,年级,班级,报告类型,报告人,报告日期,
count(处置情况) + count(缺勤原因) as 异常学生数
-- 异常学生+ 缺勤学生 count(~)不统计为null值
FROM dbo.晨午检
-- where 缺勤原因 is not NULL and 处置情况 is not NULL
group by 单位,年级,班级,报告类型,报告人,报告日期
上面二种写法结果一样,自行消化!