我有以下SQL语句:
SELECT wn_sum, COUNT(*) as count FROM cash_numbers GROUP BY wn_sum ORDER BY wn_sum ASC;
几乎可以满足我的要求,但是我想从wn_sum
中选择第100行,或者从wn_sum
中选择最后100行。
我将如何重写此语句以仅从wn_sum
获取前100行或从wn_sum
获取最后100行以获取计数?
mysql> SELECT wn_sum, COUNT(*) as count FROM cash_numbers GROUP BY wn_sum ORDER BY wn_sum ASC;
+--------+-------+
| wn_sum | count |
+--------+-------+
| 54 | 2 |
| 56 | 1 |
| 61 | 1 |
| 65 | 1 |
| 66 | 1 |
| 68 | 1 |
| 70 | 1 |
| 71 | 1 |
| 72 | 1 |
| 73 | 2 |
| 76 | 4 |
....
| 234 | 1 |
| 237 | 1 |
| 241 | 1 |
| 244 | 1 |
| 251 | 2 |
| 267 | 1 |
+--------+-------+
156 rows in set (0.00 sec)
mysql>
我确实尝试将限制设置为100,但是我的语法错误,因此在尝试使用这些限制时会出错。