case-when-then

本文介绍了一种使用SQL查询从在线学术数据中统计不同年龄段患者数量的方法。通过case语句将患者年龄划分为多个区间,然后对每个区间进行计数,最终得到各年龄段患者总数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

select t.ageRang, count(t.ageRang) as totalCount from (
select patient_name, 
case 
 when patient_age >= 20 and patient_age <= 29 then '20-29岁'
 when patient_age > 29 and patient_age <=39 then '30-39岁'
 when patient_age > 39 and patient_age <= 49 then '40-49岁'
 when patient_age > 49 and patient_age <=59 then '50-69岁'
 when patient_age > 59 then '60岁及以上'
 when (patient_age < 20 or age_unit in ('月', '天')) then '20岁以下'
 else '其它'
 end as ageRang
from online_academic_data where online_academic_id ='719'
) t group by t.ageRang
复制代码
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值