如何在SQL Server中实现 Limit m,n 的功能

如题所述

解决方案:
虽然SQL Server不支持 Limit ,但是它支持 TOP
如果要查询上述结果中前6条记录,则相应的SQL语句是
select top 6 id from tablename 
如果要查询上述结果中第 7 条到第 9 条记录,则相应的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
)

温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-12-02
select id from tablename