sql 有条件计数

 

select  InstitutionID=LEFT(InstitutionID,9), Irregularities_Type=sum(CASE WHEN Irregularities_Type>0 THEN 1 ELSE 0 END)
,Irregularities_Type2=sum(CASE WHEN Irregularities_Type2>0 THEN 1 ELSE 0 END),Irregularities_Type3=sum(CASE WHEN Irregularities_Type3>0 THEN 1 ELSE 0 END)
from
(
select IrregularitiesList.Irregularities_Type, IrregularitiesList.Irregularities_Type2,IrregularitiesList.Irregularities_Type3,IrregularitiesList.InstitutionID, IrregularitiesList.PersonnelID
,PersonList.PersonnelName,Admin_Dept.Dept_Name
from   IrregularitiesList inner join PersonList
on PersonList.PersonnelID=IrregularitiesList.PersonnelID inner join Admin_Dept
on  IrregularitiesList.InstitutionID=Admin_Dept.Dept_Id)a group by LEFT(InstitutionID,9)

 

posted on 2017-08-01 10:26  gwazy  阅读(2981)  评论(0编辑  收藏  举报

导航