declare @salary table(分公司编号 varchar(2),
部门编号 varchar(3),姓名 varchar(10),发放月份 datetime,工资 int)
insert into @salary select '01','001','张展','201101',10000
union all select '01','001','张展','201105',20000
union all select '01','002','李四','201101',50000
union all select '02','001','小红','201105',90000
union all select '02','003','晓宇','201102',30000
union all select '02','001','小黄','201102', 30000
;with tmp as(select 姓名,SUM(工资) 年收入 from @salary group by 姓名)
select 年收入额=(case
when 年收入>0 and 年收入<=30000 then '0-3万'
when 年收入>30000 and 年收入<=50000 then '3-5万'
when 年收入>50000 and 年收入<=100000 then '5-10万'
end),COUNT(1) as 人数
from tmp group by
(
case
when 年收入>0 and 年收入<=30000 then '0-3万'
when 年收入>30000 and 年收入<=50000 then '3-5万'
when 年收入>50000 and 年收入<=100000 then '5-10万'
end
)