sqlServer 查詢表中31到40的記錄,考慮id不連續的情況


SQL   查詢表中31到40的記錄,考慮id不連續的情況

寫出一條sql語句輸出users表中31到40記錄(數據庫為SQL Server,以自動增長的ID作為主鍵,注意ID可能不是連續的)?

--使用not in select top 10 * from users where id not in(select top 30 id from users order by id asc) order by id asc --使用order by select * from (select top 10 * from (select top 40 * from users order by id asc) as u order by u.id desc) as u1 order by u1.id asc --使用開窗函數 select * from(select ROW_NUMBER() over(order by id) as num, * from users)as u where u.num between 31 and 40


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM