0

如何从 MySQL 时间日期格式或 unix 时间戳将数组中的数据计数/分组为小时?

我的数组:

Array (
    [0] => Array ( 
                [0] => id
                [1] => name 
                [2] => 2013-01-10 00:36:00 
    ) 
    [1] => Array ( 
                [0] => id
                [1] => name 
                [2] => 2013-01-10 00:36:00 
    ) 
)

如何缩小这样的数千个项目并以某种方式将它们聚合到数小时甚至数天?我只需要在特定日期给定小时的粗略行数。

4

2 回答 2

1

来自@Robert Seddon-Smith 的回答中适用于我的案例的有效代码:

SELECT id, name, day, key FROM table WHERE day > '2013 6-01 00:00:00' && day < '2013-6-31 23:59:59' GROUP BY YEAR(day), MONTH(day), DAY(day ), HOUR(天), SECOND(天)

于 2013-06-21T08:17:54.563 回答
0

尝试 SELECT * from table GROUP BY HOUR(date_column) WHERE 条件...

http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_hour

于 2013-06-20T23:50:38.353 回答