最常见的小时查询?

时间:2012-03-27 14:40:40

标签: mysql datetime

我有这张桌子:

ID(INT)    DATE(DATETIME)

DATE列下有很多不同的日期,我想弄清楚表中所有行之间最常见的小时,无论哪一天。< / p>

如何使用MySQL查询执行此操作?

4 个答案:

答案 0 :(得分:5)

SELECT HOUR(date) AS hr, COUNT(*) AS cnt
FROM yourtable
GROUP BY hr
ORDER BY cnt DESC
LIMIT 1

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

答案 1 :(得分:2)

试试这个 -

SELECT HOUR(`DATE`) AS `hour`, COUNT(*)
FROM `table`
GROUP BY `hour`

答案 2 :(得分:0)

您可以执行以下查询:

  

SELECT COUNT(daterow)AS occurrences FROM table GROUP BY daterow ORDER BY occurrences DESC LIMIT 1;

答案 3 :(得分:0)

SELECT COUNT(id),HOUR(date)    来自test    GROUP BY HOUR(date)    按COUNT(id)DESC排序    限制1