select name , SUM(
case when SUBSTRING(convert(varchar(7),date,120),6,2)in ('01','02','03') then yeji else 0 end
) as '第一季度' ,
SUM(
case when SUBSTRING(convert(varchar(7),date,120),6,2) in ('04','05','06') then yeji else 0 end
) as '第二季度',
SUM(
case when SUBSTRING(convert(varchar(7),date,120),6,2) in ('07','08','09') then yeji else 0 end
) as '第三季度',
SUM(
case when SUBSTRING(convert(varchar(7),date,120),6,2) in ('10','11','12') then yeji else 0 end
) as '第四季度'
from yjcount
group by name
转载于:https://www.cnblogs.com/zqcai/archive/2012/11/26/2788574.html