Oracle中通过Group By和Case When结合使用完成区间统计

项目数据统计功能中有一个需求,需要把人员年龄分成各个年龄段后再统计数量。数据源格式:

需要统计出来的格式为:

实现sql为:

select case
         when s.age between 10 and 20 then
          '10--20'
         when s.age between 20 and 30 then
          '20-30'
       end as "年龄",
       count(*) as "人次"
  from student s
 group by case
            when s.age between 10 and 20 then
             '10--20'
            when s.age between 20 and 30 then
             '20-30'
          end

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_43888891/article/details/115690923
今日推荐