數據表中比如有20條數據
讀取前5條數據
select top 5 * from 表 order by id desc
讀取前5條數據後的5條數據
(就是查詢前10條記錄,取後面5個)
select top 5 * from 表 where
id not in (select top 5 id from 表)
===================================================================================
SELECT TOP 11 * FROM (
SELECT ROW_NUMBER() OVER (ORDER BY StuID) AS RowNumber, *
FROM StuInfo) t
WHERE RowNumber >= 10
假設StuID是StuInfo表的主鍵“學號”。先按學號排序,生成行號,再返回行號>=10時的前11條記錄,即行號為10~20的11條記錄。
=======================================================================
select top 10 * from [table_name] where id in (select top 20 id from [table_name] order by id desc) order by id asc
這樣顯示出來的就是:從11到20條數據