日期:2014-05-18  浏览次数:20514 次

求一统计查询的SQL

如图,按照班级号Class_fk查询出每个班级的班主任到岗和缺岗统计情况,该SQL如何写?
请高手指教!

------解决方案--------------------
SQL code
select Class_fk as 班级,
查早操到岗次数=sum(case when MornExercise='到岗' then 1 else 0 end),
查早操缺岗次数=sum(case when MornExercise='缺岗' then 1 else 0 end),
查公寓到岗次数=sum(case when ApartCheck='到岗' then 1 else 0 end),
查公寓缺岗次数=sum(case when ApartCheck='缺岗' then 1 else 0 end)
from tb
group by Class_fk

------解决方案--------------------
探讨
SQL code

select Class_fk as 班级,
查早操到岗次数=sum(case when MornExercise='到岗' then 1 else 0 end),
查早操缺岗次数=sum(case when MornExercise='缺岗' then 1 else 0 end),
查公寓到岗次数=sum(case when ApartCheck='到岗' then……

------解决方案--------------------
探讨
SQL code
select Class_fk as 班级,
查早操到岗次数=sum(case when MornExercise='到岗' then 1 else 0 end),
查早操缺岗次数=sum(case when MornExercise='缺岗' then 1 else 0 end),
查公寓到岗次数=sum(case when ApartCheck='到岗' then 1……