Group by:
SELECT COUNT(`id`) AS `Records`, DATE(FROM_UNIXTIME(`date`)) AS `Date` FROM `table` GROUP BY DATE(FROM_UNIXTIME(`date`))
Conclusion:
Records | Date -------------------------------- 10 | 2011-10-19 10 | 2011-10-18
Sort by:
SELECT `id`, FROM_UNIXTIME(`date`) AS `Date` FROM `table` ORDER BY DATE(FROM_UNIXTIME(`date`)) [ASC|DESC]
(Although in fact you would get the same order using only FROM_UNIXTIME () or the raw date
value, since they would all flush correctly in an attempt to order)
Conclusion:
id | Date -------------------------------- 03 | 2011-10-19 12:00:00 02 | 2011-10-18 12:00:00 01 | 2011-10-17 12:00:00
This converts the unix timestamp to mysql datetime, and then extracts the date value from the one that applies to the grouping or order clause
If you want to group by day, regardless of month or year, use DAY () instead of DATE ()
However, could you tell us which group is βevery day in a rowβ. what result do you want to show? when you group something, you use some kind of aggregate processor, such as COUNT () or SUM () in the field inside the group.
MySQL Group Function Reference
MySQL Date and Time Function Reference
source share