case when用法

提问:
select 

case  salary
      when 5000  then  '高薪'
      when 4500  then  '中薪'
      when 3500  then  '中低薪'
      else 'null'
      end as '工资等级' 
      
from  telenolist
我想统计各个工资级别的人数    那个count(*)应该放在语句的哪里,还用再填写别的语句吗?。先谢谢了
 

   

   回答:

select 
count(*) as cnt,
case  salary
      when 5000  then  '高薪'
      when 4500  then  '中薪'
      when 3500  then  '中低薪'
      else 'null'
      end as '工资等级' 
      
from  telenolist
group by  case  salary
      when 5000  then  '高薪'
      when 4500  then  '中薪'
      when 3500  then  '中低薪'
      else 'null'
      end

猜你喜欢

转载自ayangtian.iteye.com/blog/1440577