शायद आप यही चाहते हैं:
SELECT
5 * (n div 5) as 'from',
5 * (n div 5) + 4 as 'to',
COUNT(*)
FROM yourtable
GROUP BY n div 5;
आपके नमूने के लिए यह क्वेरी आपको देती है
+------+------+----------+
| from | to | count(*) |
+------+------+----------+
| 0 | 4 | 3 |
| 5 | 9 | 4 |
| 10 | 14 | 2 |
| 15 | 19 | 1 |
+------+------+----------+
4 rows in set (0.00 sec)