How to group by month from Date field using sql

前端 未结 10 2082
自闭症患者
自闭症患者 2020-11-30 23:39

How can I group only by month from a date field (and not group by day)?

Here is what my date field looks like:

2012-05-01

Here is m

10条回答
  •  鱼传尺愫
    2020-12-01 00:28

    Use the DATEPART function to extract the month from the date.

    So you would do something like this:

    SELECT DATEPART(month, Closing_Date) AS Closing_Month, COUNT(Status) AS TotalCount
    FROM t
    GROUP BY DATEPART(month, Closing_Date)
    

提交回复
热议问题