sql 有条件计数
Posted boytomato
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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)
以上是关于sql 有条件计数的主要内容,如果未能解决你的问题,请参考以下文章