MySQL Query GROUP BY day / month / year

前端 未结 14 2361
野趣味
野趣味 2020-11-22 06:37

Is it possible to make a simple query to count how many records I have in a determined period of time like a year, month, or day, having a TIMESTAMP field, like

14条回答
  •  失恋的感觉
    2020-11-22 07:00

    Complete and simple solution with similarly performing yet shorter and more flexible alternative currently active:

    SELECT COUNT(*) FROM stats
    -- GROUP BY YEAR(record_date), MONTH(record_date), DAYOFMONTH(record_date)
    GROUP BY DATE_FORMAT(record_date, '%Y-%m-%d')
    

提交回复
热议问题