sql问题

select  

      sum(case when record like '%博士%' then 1 else 0 end) 博士,

      sum(case when record like '%硕士%' then 1 else 0 end) 硕士,

      sum(case when record like '%本科%' then 1 else 0 end) 本科,

      sum(case when record not like '%博士%' and record not like '%硕士%' and record not like '%本科%' then 1 else 0 end) 专科及以下

from dw.dw_hr_new_emp 

where yearmonth<='${yearmonth}' 

      and left(yearmonth,4)=to_char(now(),'yyyy') 

group by 

      case when record like '%博士%' then 1 else 0 end,

      case when record like '%硕士%' then 1 else 0 end,

      case when record like '%本科%' then 1 else 0 end,

      case when record not like '%博士%' and record not like '%硕士%' and record not like '%本科%' then 1 else 0 end 

image.png

  1. 想把他们合成一行展示。

  2. 专科及以下的人数算出来的结果不对,不知道是不是过滤出了问题

宝贝 发布于 2020-10-13 15:44
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共2回答
最佳回答
1
北纬六十六度Lv4初级互助
发布于2020-10-13 15:50

去掉 group by

最佳回答
0
lincoderLv5初级互助
发布于2020-10-13 15:46

你这个是不是要加一个唯一标识啊去group by 比如加一个id啊啥的

  • 宝贝 宝贝(提问者) 嗯,就是多加了分组,我忘了我把 count删掉了
    2020-10-13 16:02 
  • 3关注人数
  • 272浏览人数
  • 最后回答于:2020-10-13 15:50
    请选择关闭问题的原因
    确定 取消
    返回顶部