MariaDB [test]> select cnt,min(nr),max(nr),count(nr) from gb group by cnt having cnt < 16 order by cnt; +-----+---------+---------+-----------+ | cnt | min(nr) | max(nr) | count(nr) | +-----+---------+---------+-----------+ | 1 | 4 | 12 | 4 | | 2 | 10 | 68 | 9 | | 3 | 22 | 128 | 11 | | 4 | 34 | 152 | 11 | | 5 | 48 | 188 | 16 | | 6 | 60 | 332 | 16 | | 7 | 78 | 398 | 18 | | 8 | 84 | 368 | 20 | | 9 | 90 | 488 | 23 | | 10 | 114 | 632 | 16 | | 11 | 144 | 692 | 29 | | 12 | 120 | 626 | 16 | | 13 | 168 | 992 | 25 | | 14 | 180 | 878 | 27 | | 15 | 234 | 908 | 23 | +-----+---------+---------+-----------+ 15 rows in set (1.21 sec)