我在mssql表中有一个列'last_updated',我想从列中选择几个月,并计算有多少个月:
24/09/2011 22:34:20
24/09/2011 22:35:50
15/10/2011 14:06:43
15/09/2011 18:42:32
18/10/2011 00:37:41
所以在上面的专栏中你会有
月| Occurances
9 | 3
10 | 2
我是如何提取这些信息的?
答案 0 :(得分:2)
SELECT MONTH(DateColumn) AS MonthNumber, COUNT(1) AS Occurances
FROM schema.TableName
GROUP BY MONTH(DateColumn)