Retrieve rows grouped by hour with MySQL

后端 未结 2 1950
暖寄归人
暖寄归人 2021-02-04 10:40

I have a table containing access logs. I want to know how many accesses to resource_id \'123\' occured in each hour in a 24 hour day.

My first thought for retrieving thi

相关标签:
2条回答
  • 2021-02-04 10:49

    You can use the function HOUR to get the hour out of the time. Then you should be able to group by that.

    0 讨论(0)
  • 2021-02-04 11:02
    SELECT HOUR(MyDatetimeColumn) AS h, COUNT(*)
    FROM MyTable
    GROUP BY h;
    
    0 讨论(0)
提交回复
热议问题