范围年龄的查询很常用
select case when (to_char(sysdate, 'yyyy' )-to_char(t.csrq,'yyyy')) BETWEEN 18 AND 30 then '18-30岁'
when (to_char(sysdate, 'yyyy' )-to_char(t.csrq,'yyyy')) BETWEEN 31 AND 41 then '31-41岁'when (to_char(sysdate, 'yyyy' )-to_char(t.csrq,'yyyy')) > 41 then '41岁以上' end as 年龄段,count(*)人数
from lds_employment_info t
group by case when (to_char(sysdate, 'yyyy' )-to_char(t.csrq,'yyyy')) BETWEEN 18 AND 30 then '18-30'when (to_char(sysdate, 'yyyy' )-to_char(t.csrq,'yyyy')) BETWEEN 31 AND 41 then '31-41'
when (to_char(sysdate, 'yyyy' )-to_char(t.csrq,'yyyy')) > 41 then '41以上' end
order by 年龄段
//when右边的括号意思是(当前系统的年份-一个Date字段的年份)
//PLSQL 结果如下:
本文介绍了一种使用SQL查询按年龄区间统计人数的方法。通过计算当前年份与出生日期之间的差值来确定员工的年龄段,并根据不同的年龄段进行分组计数。
2444

被折叠的 条评论
为什么被折叠?



