mysql中一張(居民)表按年齡段查詢數據


知識點:

    用mysql,按年齡段查詢一張居民的數據(各年齡段居民的個數)

 

 

1.如:查詢resident(居民表),按照各年齡段,統計人數

2.mysql語句如下:

select ageproportion as '年齡段',count(*) as '人數' from
(
     SELECT
     CASE
       when age>0 and age<=10 then '0-10歲'
       when age>10 and age<=20 then '10-20歲'
       when age>20 and age<=30 then '20-30歲'
       when age>30 and age<=40 then '30-40歲'
       when age>40 and age<=50 then '40-50歲'
       when age>50 and age<=60 then '50-60歲'
       else '60歲以上'
      
     END
     as ageproportion from resident
)a GROUP BY ageproportion 

 

3.查詢結果:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM