当前位置: 首页  >  SqlServer  >  用T-SQL查询表中第n行到第m行数据的写法示例

用T-SQL查询表中第n行到第m行数据的写法示例 TOP

假设这里的n=6,m=10则有以下两种写法,qusID可以不连续,如下:

select top 5 * from tb_wenti where qusID not in(select top 5 qusID from tb_wenti);

select top 5 * from tb_wenti where qusID in(select top 10 qusID from tb_wenti) order by qusID desc;

一般的写法为

select top m-n+1 * from tablename where id not in(select top n-1 id from tablename);

select top m-n+1 * from tablename where id in(select top m id from tablename) order by id desc;

Views:819   Posted at:2013-11-28
收藏 推荐 打印 | 录入:Admin | 阅读:0