[英]How to select set of data from a table from nth row to 1st row
I have written a query to select set of data from nth to last record like below 我写了一个查询,从第n个记录到最后一个记录选择数据集,如下所示
select station_code from route_master where route_code = "102D" and sequence_no limit "5", "100";
route_master
route_master
route_code
route_code
Now I want to select data from nth to 1st row. 现在我要从第n到第1行选择数据。
You can just use a plain LIMIT
command along with a subquery which imposes the reverse ordering: 您可以仅使用普通的
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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.