sql list每年出生的人数

时间:2013-09-12 03:42:59

标签: sql

我有一张桌子,上面有两列,名字和出生年份(1960 - 1980年)。如何编写每年列出的单个SQL查询以及当年出生的人数?类似的东西:

      Year     Number of people born
      1960     5
      1961     3
      1962     4
      ...      ..
      1980     4

3 个答案:

答案 0 :(得分:2)

Select Year, Count(*) as 'Number of people born' From SomeTable
GROUP BY Year
ORDER BY Year ASC

答案 1 :(得分:0)

SELECT YEAROFBIRTH, COUNT(*) FROM YOURTABLE GROUP BY YEAROFBIRTH

答案 2 :(得分:0)

您可以尝试以下代码:

SELECT MONTH(BIRTHDAY), COUNT(*)
FROM STUDENT
GROUP BY MONTH(BIRTHDAY)