我在使用日期时间值时遇到问题。我想找出哪个小时的搜索次数最多 这是一些示例数据
Srch_id dttime
1 2013-04-04 08:32:15
1 2013-04-04 08:32:15
1 2013-04-04 08:32:15
1 2013-04-04 08:32:15
2 2012-12-31 08:59:22
2 2012-12-31 08:59:22
2 2012-12-31 08:59:22
3 2013-12-31 09:22:22
3 2013-12-31 09:22:22
这就是我想要的结果
Searches HourofSearch
7 08
从表中选择 srch_id,(小时(dttime)...不知道从这里去哪里
最佳答案
按小时分组,按每个计数排序并仅取第一条记录
select hour(dttime) as HourofSearch, count(*) as Searches
from your_table
group by hour(dttime)
order by count(*) desc
limit 1
Here是一个工作示例。
关于MYSQL - 如何查找哪个小时搜索次数最多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33443215/