MySQL 查询每日每小时峰值
黄舟
黄舟 2017-04-17 11:24:34
0
1
334

现在的查询方法是这样的:

SELECT COUNT(r.user_id) AS users
FROM record r
WHERE r.created BETWEEN :date_from AND :date_till
GROUP BY HOUR(r.created)
ORDER BY users DESC
LIMIT 1

但这样如果查询多天的峰值就要循环执行多次查询,是否有更高效的方法?

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

全部回复(1)
Peter_Zhu

假设 r.created 是类似 2014-04-03 09:04:00

SELECT COUNT(r.user_id) AS users, HOUR(r.created) data_hour, FROM_UNIXTIME(unix_timestamp(r.created), "%Y-%m-%d") data_date
FROM record r
WHERE r.created BETWEEN :date_from AND :date_till
GROUP BY data_hour, data_date
ORDER BY data_date, users, data_hour DESC
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!