我不是 MySql 的专家。我正在尝试将表中的数据拆分为基于account_no
. 这是我的桌子。
mysql> select * from manager;
+----+-------+------------+
| id | name | account_no |
+----+-------+------------+
| 1 | John | 5 |
| 2 | Peter | 15 |
| 3 | Tony | 18 |
| 4 | Mac | 35 |
| 5 | Max | 55 |
| 6 | Smith | 58 |
+----+-------+------------+
如您所见,account_no
是一个正数。我想根据account_no将这些记录分成 10 批并显示该范围内的计数。
对于0到10
之间
的示例, 11到20
之间只有1条记录21到30
之间有2条记录没有记录* (所以应该省略。) *
等等...实际上我希望得到一个输出像这样。
+-------------+-----------+-------+
| range_start | range_end | count |
+-------------+-----------+-------+
| 1 | 10 | 1 | -> because there is 1 record between 1 and 10
| 11 | 20 | 2 | -> because there are 2 records between 11 and 20
| 31 | 40 | 1 | -> because there is 1 record between 31 and 40
| 51 | 60 | 2 | -> because there are 2 records between 51 and 60
+-------------+-----------+-------+
我尝试了几种组合,但所有组合都只给我一行结果。
有谁能够帮助我?