最新消息:iOS编程开发交流群(6906921) ,Mac.Cocoa开发交流群(7758675) 欢迎iOS/macOS开发编程爱好及学习者加入!

sql根据出生日期按年龄段统计用户

数据库 天狐 9621浏览 0评论
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根据出生日期按年龄段统计用户

微信 OR 支付宝 扫描二维码
为天狐 打赏
非常感谢你的支持,哥会继续努力!
发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址