3 回答

TA貢獻1784條經(jīng)驗 獲得超9個贊
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | 解決方案: 雖然SQL Server不支持 Limit ,但是它支持 TOP 如果要查詢上述結(jié)果中前6條記錄,則相應(yīng)的SQL語句是 select top 6 id from tablename 如果要查詢上述結(jié)果中第 7 條到第 9 條記錄,則相應(yīng)的SQL語句是: select top 3 id from tablename where id not in ( select top 6 id from tablename ) 以此類推: select top (n-m+1) id from tablename where id not in ( select top m-1 id from tablename ) |

TA貢獻1827條經(jīng)驗 獲得超4個贊
select top (n-m+1) id from tablename
where id not in (
select top m-1 id from tablename
)

TA貢獻1788條經(jīng)驗 獲得超4個贊
假設(shè)頁數(shù)是10,現(xiàn)在要拿出第5頁的內(nèi)容,查詢語句如下:
--10代表分頁的大小
select top 10 *
from test
where id not in
(
--40是這么計算出來的:10*(5-1)
select top 40 id from test order by id
)
order by id
原理:需要拿出數(shù)據(jù)庫的第5頁,就是40-50條記錄。首先拿出數(shù)據(jù)庫中的前40條記錄的id值,然后再拿出剩余部分的前10條元素
- 3 回答
- 0 關(guān)注
- 1452 瀏覽
添加回答
舉報