现在我已经获得了以下(我的)SQL语句,它根据小时返回托管数量。
SELECT
COUNT(*) AS amount
HOUR(date) AS hour
-- [1]
FROM
table
GROUP BY
HOUR(date)
但我实际上想要另一个包含小时出现天数的结果。基本上是这样的:
[1] = COUNT(DAY(date), MONTH(date), YEAR(date)) AS day_count
示例:
id | date
0 | 01/01/2001 5:15
1 | 01/01/2001 5:10
2 | 01/01/2001 6:03
3 | 01/01/2001 7:04
4 | 02/01/2001 5:00
应该返回
amount | hour | day_count
3 | 5 | 2
1 | 6 | 1
1 | 7 | 1
答案 0 :(得分:0)
我认为你只需要按小时和日期分开日子,并按他们分组......
SELECT count(*) as `amount`
, count(hour(date)) as `Hour`
, count(day(date)) as `Day_Count`
FROM table
GROUP BY hour(Date), day(date)