在表格中有两列:Datestamp
,如2012-12-16,类型为date
,Timestamp
,如12:22:59,类型为time
。是否可以使用1 sql获取特定日期每小时的行数?返回时我需要获得24个号码。
答案 0 :(得分:2)
这样的事情:
SELECT COUNT(*) FROM your_table
WHERE `Datestamp` = '2012-12-16'
GROUP BY HOUR(`Timestamp`)
答案 1 :(得分:0)
SELECT datestamp as day, hour(timestamp) as hour, count(*)
FROM your_table
GROUP BY datestamp, hour(timestamp)