1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
select nnd as age ,count(*) as num from ( select case when to_char(sysdate,'yyyy')-to_char(BIRTHDAY,'yyyy') >= '0' and to_char(sysdate,'yyyy')-to_char(BIRTHDAY,'yyyy') <= '10' then '10岁以下' when to_char(sysdate,'yyyy')-to_char(BIRTHDAY,'yyyy') >= '11' and to_char(sysdate,'yyyy')-to_char(BIRTHDAY,'yyyy')<='20' then '11-20' when to_char(sysdate,'yyyy')-to_char(BIRTHDAY,'yyyy') >= '21' and to_char(sysdate,'yyyy')-to_char(BIRTHDAY,'yyyy')<='30' then '21-30' when to_char(sysdate,'yyyy')-to_char(BIRTHDAY,'yyyy') >= '31' and to_char(sysdate,'yyyy')-to_char(BIRTHDAY,'yyyy')<='40' then '31-40' when to_char(sysdate,'yyyy')-to_char(BIRTHDAY,'yyyy') >= '41' and to_char(sysdate,'yyyy')-to_char(BIRTHDAY,'yyyy')<='50' then '41-50' when to_char(sysdate,'yyyy')-to_char(BIRTHDAY,'yyyy') >= '51' and to_char(sysdate,'yyyy')-to_char(BIRTHDAY,'yyyy')<='60' then '51-60' when to_char(sysdate,'yyyy')-to_char(BIRTHDAY,'yyyy') >'60' then '60以上' end as nnd,fname from pcm_friends ) a group by nnd |
转载请注明:天狐博客 » sql根据出生日期按年龄段统计用户