A Blog Of Random Coding Techniques & Experiments Robert Askam

MySQL query to group by month Post MySQL query to group by month 1 week ago

A simple query that may save some time. To count all data in a table and group by a month this year from a MySQL date time. i.e 2018-11-29 10:17:30. You can use the following query.

SELECT 
MONTH(DATE COLUMN NAME HERE), count(*)
FROM
YOUR TABLE
GROUP BY YEAR(DATE COLUMN NAME HERE) , MONTH(DATE COLUMN NAME HERE)
ORDER ID id DESC