MySQL/SQL: Group by date only on a Datetime column

前端 未结 4 1018
逝去的感伤
逝去的感伤 2020-11-28 18:26

Having a table with a column like: mydate DATETIME ...

I have a query such as:

SELECT SUM(foo), mydate FROM a_table GROUP BY a_table.myd         


        
4条回答
  •  暖寄归人
    2020-11-28 18:50

    I found that I needed to group by the month and year so neither of the above worked for me. Instead I used date_format

    SELECT date
    FROM blog 
    GROUP BY DATE_FORMAT(date, "%m-%y")
    ORDER BY YEAR(date) DESC, MONTH(date) DESC 
    

提交回复
热议问题