分组间隔5分钟的蛋糕

时间:2016-09-07 12:30:30

标签: cakephp-3.0

SELECT
    timestamp, 
    name,
    count(b.name)
FROM time a, id 
WHERE …
GROUP BY 
UNIX_TIMESTAMP(timestamp) DIV 300, name

enter image description here

我上面有桌子 并希望计算created_at列  分组为created_at的5分钟间隔,  比如计数create_at列  从2016-09-01 16:21:292016-09-01 16:26:29

1 个答案:

答案 0 :(得分:0)

你必须使用FLOOR()函数来获取每五分钟一次的唯一整数

SELECT timestamp, name, count(b.name) FROM time a, id WHERE … GROUP BY FLOOR(UNIX_TIMESTAMP(timestamp)/300)