How to group by month from Date field using sql

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

    You can do this by using Year(), Month() Day() and datepart().

    In you example this would be:

    select  Closing_Date, 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 Year(Closing_Date), Month(Closing_Date), Category
    

提交回复
热议问题