[英]SQL group: count multiple things
Right now I've got the following (My)SQL-Statement which returns the amount of entrys based on hour. 现在,我有以下(My)SQL语句,它根据小时返回条目的数量。
SELECT
COUNT(*) AS amount
HOUR(date) AS hour
-- [1]
FROM
table
GROUP BY
HOUR(date)
But I actually want another result that contains the amount of days the hour appeared. 但是我实际上想要另一个包含小时显示天数的结果。 Basicly something like:
基本上像这样:
[1] = COUNT(DAY(date), MONTH(date), YEAR(date)) AS day_count
Example: 例:
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
Should return 应该回来
amount | hour | day_count
3 | 5 | 2
1 | 6 | 1
1 | 7 | 1
I think you just need to part out the days by hour and day, and group by them... 我认为您只需要逐日逐日分组,然后按分组...
SELECT count(*) as `amount`
, count(hour(date)) as `Hour`
, count(day(date)) as `Day_Count`
FROM table
GROUP BY hour(Date), day(date)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.