表A
id name 工资 部门
1 aa 2000 开发
2 bb 3000 销售
3 cc 2000 开发
4 dd 5000 销售
5 ee 8000 技术
6 ff 3500 技术 实现成
部门 2000~4000  4001~6000 6001~8000
开发 2人  0人    0人
销售 1人  1人    0人
技术 0人  0人    2人

解决方案 »

  1.   


    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 部门
      

  2.   

    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
      

  3.   

    都不好用,我家里就sql server,实现不了,报错。
      

  4.   


    sql server 跑oracle板块来问...
      

  5.   

    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
      
     with a 什么意思 from dual dual在哪弄的