How to group by month from Date field using sql

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

    Try this:

    select min(closing_date), date_part('month',closing_date) || '-' || date_part('year',closing_date) AS month,
    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 month, Category,
    ORDER BY 1
    

    This way you are grouping by a concatenated date format, joined by a -

提交回复
热议问题