简体   繁体   English

按小时选择摘要并对行进行分组

[英]Select and group rows in summary by hour

I have a table containing view/click records. 我有一个包含视图/点击记录的表。 The time is stored in a unix timestamp and I need to be able to pull out all of them within the specific month/day (based off of timestamps), but more importantly and the part I don't know how to do is group them by hour. 时间存储在unix时间戳中,我需要能够在特定的月/日内(根据时间戳)提取所有时间,但更重要的是,我不知道该怎么做的部分是将它们分组按小时计算。 I need to be able to do this in a single query rather than looping through each hour. 我需要能够在一个查询中执行此操作,而不是循环每小时。

Database is MySQL, language is PHP. 数据库是MySQL,语言是PHP。

select hour(somedate), count(*) from yourtable group by hour(somedate)

如果你需要这三个:

select month(somedate), day(somedate), hour(somedate), count(*) from yourtable group by month(somedate), day(somedate), hour(somedate)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM