How to Group Data Month when Using Datetime Column MySQL >
I'm running MySQL and I have a table titled Datetime in YYYY-MM-DD HH:MM:SS format. How can I group the Data Month on Datetime Column?
I'm running MySQL and I have a table titled Datetime in YYYY-MM-DD HH:MM:SS format. How can I group the Data Month on Datetime Column?
Try this:
GROUP BY date(ActionTime) or:
Assuming you store the date and time under the datetime column, to query it you want to count the results according to group by date, below is the format:
SELECT DATE_FORMAT(postdate, '%Y-%m-%d') AS dd, COUNT(id) FROM MyTable GROUP BY dd;
Or you can also try the upgraded query and use the string below:
SELECT substring(postrdate, 1,10) AS dd, COUNT(id) FROM MyTable GROUP BY dd;
This works faster than the first, but whichever works for you, will do.
For more information, click the link below: