簡體   English   中英

MYSQL-如何查找哪個小時的搜索次數最多

[英]MYSQL - How to find which hour has the most number of searches

我在使用日期時間值時遇到麻煩。 我想找到搜索次數最多的時間這是一些示例數據

 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,(從表中選擇hour(dttime)...不確定從這里去哪里

按小時分組,按計數排序,僅記錄第一條記錄

select hour(dttime) as HourofSearch, count(*) as Searches
from your_table
group by hour(dttime)
order by count(*) desc
limit 1

是一個工作示例。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM