3,491
社区成员
发帖
与我相关
我的任务
分享
with A as(
select 1 id, 'aa' name, 2000 工资, '开发' 部门 from dual
union all
select 2, 'bb', 3000, '销售' from dual
union all
select 3, 'cc', 2000, '开发' from dual
union all
select 4, 'dd', 5000, '销售' from dual
union all
select 5, 'ee', 8000, '技术' from dual
union all
select 6, 'ff', 3500, '技术' from dual
)
select 部门,
count(case when 2000<=工资 and 工资<4000 then 1 else null end) "2000~4000",
count(case when 4001<=工资 and 工资<6000 then 1 else null end) "4001~6000",
count(case when 6001<=工资 and 工资<8000 then 1 else null end) "6001~8000"
from a
group by 部门
部门 2000~4000 4001~6000 6001~8000
--------------------------------------------
开发 2 0 0
技术 1 0 0
销售 1 1 0
select 部门,
count(case when 2000<=工资<4000 then 1 else null end) 2000~4000,
count(case when 4001<=工资<6000 then 1 else null end) 4001~6000,
count(case when 6001<=工资<8000 then 1 else null end) 6001~8000
from tb
group by 部门