SQL Sever2005如何从表A中查询出第30到第39条记录(id是自动增长的但是现在不连续)

2025-03-03 18:55:03
推荐回答(3个)
回答1:

1: select top 9 * from (select top 39 * from A order by id asc) t order by id desc

2: select top 9 * from A where id not in (select top 30 id from A order by id asc) order by id asc

3: select * from (select *, ROW_NUMBER() OVER (order by id asc) as rownum from A) t where rownum > 30 and rownum <=39

自己定义好顺序。

回答2:

只知道2000的..利用TOP的子查询~~听说2005推出了ROW_NUMBER函数...我看了下..没看懂

TOP的子查询思路是

Select Top 10 * From Table Where id Not In (Select Top 50 id From Table)

意思是从偏移量50开始取10条记录~~(偏移量从0开始计算)

回答3:

流香羽 的回答是正确的 不过
30到39 是 10条数据吧!!