mysql统计各年龄段的数量
生活随笔
收集整理的這篇文章主要介紹了
mysql统计各年龄段的数量
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.統計各年齡段的人數。1-10,11-20,20+,我用的是CASE WHEN的方式實現的。
select age_temp,count(*) as total from ( select age, case when age between 1 and 10 then '1-10' when age between 11 and 20 then '11-20' when age >20 then '20+' end as age_temp from user )t_user group by age_temp;2.查詢用戶信息,并標明用戶年齡處于哪個年齡段,1-10,11-20,20+。
select *, case when age between 1 and 10 then '1-10' when age between 11 and 20 then '11-20' when age >20 then '20+' end as age_range from user;?
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的mysql统计各年龄段的数量的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 在大城市租房需要什么技巧和注意事项
- 下一篇: 现实中女人为什么要买房?