我有一个包含两列的表,名称和出生年份(从 1960 年到 1980 年)。如何编写一个列出每年和当年出生人数的单个 sql 查询?就像是:
Year Number of people born
1960 5
1961 3
1962 4
... ..
1980 4
我有一个包含两列的表,名称和出生年份(从 1960 年到 1980 年)。如何编写一个列出每年和当年出生人数的单个 sql 查询?就像是:
Year Number of people born
1960 5
1961 3
1962 4
... ..
1980 4
Select Year, Count(*) as 'Number of people born' From SomeTable
GROUP BY Year
ORDER BY Year ASC
SELECT YEAROFBIRTH, COUNT(*) FROM YOURTABLE GROUP BY YEAROFBIRTH
你可以试试这段代码:
SELECT MONTH(BIRTHDAY), COUNT(*)
FROM STUDENT
GROUP BY MONTH(BIRTHDAY)