[英]Grouping 24 hours time by range
I have a number of rows that are in 24 hour format like this 我有很多这样的24小时格式的行
What i would like is to have a format like this one 我想要的是这样的格式
+------+------+----------+
| from | to | count(*) |
+------+------+----------+
| 0000 | 0100| 3 |
| 0100 | 0200 | 4 |
| 0200| 0300 | 2 |
| 0300 | 0400 | 1 |
+------+------+----------+
I have tried this 我已经试过了
SELECT COUNT(*) `count`,
100*FLOOR(the_amount/100) `from`,
100*FLOOR(the_amount/100)+99 `to`
FROM r_data
where transaction_type = 'send'
GROUP BY FLOOR(the_amount/100) ORDER BY COUNT(*) DESC
but this gives only one row.How should i write a query to group my time that is in 24 hour format?. 但这仅给出一行。我应该如何编写查询以将我的时间以24小时格式分组?
Try this: 尝试这个:
SELECT
LPAD(100*FLOOR(24_hour_time/100),4,0) AS `from`,
LPAD(100*FLOOR(24_hour_time/100) + 100,4,0) AS `to`,
COUNT(*) AS `count`
FROM
r_data
WHERE
transaction_typ = 'send'
GROUP BY 1
ORDER BY 24_hour_time;
But it will only show you "populated hours". 但这只会显示“人口稠密的小时”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.