group by 的应用

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
  )
年收入额 人数
0-3万	  3
3-5万	  1
5-10万	  1


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值