按范围对 24 小时时间进行分组

Grouping 24 hours time by range

我有很多这样的 24 小时格式的行

我想要的是像这样的格式

+------+------+----------+
| from | to   | count(*) |
+------+------+----------+
| 0000 |  0100|        3 |
| 0100 | 0200 |        4 |
|  0200| 0300 |        2 |
| 0300 | 0400 |        1 |
+------+------+----------+

我试过了

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

但这只给出了一个 row.How 我应该写一个查询来对我的 24 小时格式的时间进行分组吗?

试试这个:

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;

但它只会显示给你"populated hours"。