0

我有一个包含两列的表,名称和出生年份(从 1960 年到 1980 年)。如何编写一个列出每年和当年出生人数的单个 sql 查询?就像是:

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

3 回答 3

2
Select Year, Count(*) as 'Number of people born' From SomeTable
GROUP BY Year
ORDER BY Year ASC
于 2013-09-12T03:44:32.670 回答
0
SELECT YEAROFBIRTH, COUNT(*) FROM YOURTABLE GROUP BY YEAROFBIRTH
于 2013-09-12T03:44:53.707 回答
0

你可以试试这段代码:

SELECT MONTH(BIRTHDAY), COUNT(*)
FROM STUDENT
GROUP BY MONTH(BIRTHDAY)
于 2015-06-29T08:51:08.787 回答