现在的位置: 首页 > 综合 > 正文

使用sql查询表中第m行至n行的数据

2018年05月03日 ⁄ 综合 ⁄ 共 247字 ⁄ 字号 评论关闭

对于sqlserver2000,使用如下语句实现:

select * from

(
select *, couts=(select count(*)+1 from table where  id<t1.id) from table t1

) t2

where  couts between m and n

 

对于sqlserver2005,使用如下语句实现:

select * from

(

select  *,couts=row_number()+1 over(order by id) from table

) t

where couts between m and n

 


抱歉!评论已关闭.