美文网首页
oracle中通过出生日期分组

oracle中通过出生日期分组

作者: 盗生一 | 来源:发表于2020-11-12 12:47 被阅读0次
    • 通过sql分组不是太好,通过业务进行分组,就是说通过年龄分组,在代码中在控制
    • 通过年龄分组
    select count(1) as RYXXBZ,age as XM from(SELECT TRUNC(months_between(sysdate, birthday)/12) AS age from TEST_TABLE) group by age order by count(1) asc
    
    image.png
    
    select case 
        when age between 0 and 1 then '青年' 
        when age between 2 and 5 then '中年' 
        when age>=6 then '老年' end as 年龄段,
    count(*) as 人数 
    from (SELECT TRUNC(months_between(sysdate, birthday)/12) AS age from TEST_TABLE)
    group by case 
         when age between 0 and 1 then '青年' 
        when age between 2 and 5 then '中年' 
        when age>=6 then '老年' 
    end;
    
    image.png

    相关文章

      网友评论

          本文标题:oracle中通过出生日期分组

          本文链接:https://www.haomeiwen.com/subject/fmtpbktx.html