zoukankan      html  css  js  c++  java
  • 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.查询结果:

  • 相关阅读:
    过河卒 题解
    You Are the One solution
    D
    Find a way solution
    A
    入门训练 Fibonacci数列
    求平均成绩 题解
    海选女主角 题解
    子集生成和组合问题
    log4j
  • 原文地址:https://www.cnblogs.com/shuaifing/p/8598254.html
Copyright © 2011-2022 走看看