【SQL查询】查询列中使用条件逻辑_case when then end

select x.范围, count(*)
  from (select t.ename,
               case
                 when t.sal <= 1000 then
                  '0-1000'
                 when t.sal <= 2000 then
                  '1000-2000'
                 when t.sal <= 3000 then
                  '2000-3000'
                 when t.sal <= 4000 then
                  '3000-4000'
                 when t.sal <= 5000 then
                  '3000-4000'
                 ELSE
                  '太高'
               END as 范围
          from emp t) x
 group by x.范围
 order by x.范围;

原文地址:https://www.cnblogs.com/zhuhaiying/p/7910050.html