我编写了一个查询来选择从第 n 条到最后一条记录的数据集,如下所示
select station_code from route_master where route_code = "102D" and sequence_no limit "5", "100";
- 表名称:
route_master
- 列名称:
route_code
现在我想选择从第n行到第1行的数据。
最佳答案
您可以仅使用简单的LIMIT
命令以及强制反向排序的子查询:
SELECT station_code
FROM
(
SELECT station_code, sequence_no
FROM route_master
WHERE route_code = '102D'
ORDER BY sequence_no
LIMIT n
) t
ORDER BY sequence_no DESC;
关于mysql - 如何从表中选择第n行到第1行的数据集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47406318/