How to group by month from Date field using sql

前端 未结 10 2067
自闭症患者
自闭症患者 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:23

    SQL Server 2012 version above,

    SELECT  format(Closing_Date,'yyyy-MM') as ClosingMonth,
            Category,  
            COUNT(Status) TotalCount 
    FROM    MyTable
    WHERE   Closing_Date >= '2012-02-01' 
    AND     Closing_Date <= '2012-12-31'
    AND     Defect_Status1 IS NOT NULL
    GROUP BY format(Closing_Date,'yyyy-MM'), Category;
    

提交回复
热议问题