http://www.cnblogs.com/puresoul/archive/2010/06/24/1764249.html
题目:
写出一条Sql语句:
取出表A中第31到第40记录(SQLServer, 以自动增长的ID作为主键, 注意:ID可能不是连续的。)
解答(已测试):
1、假设ID是连续的:
select top 10 * from A where ID not in (select top 30 ID from A)
或
select * from A where ID between 31 and 40
2、假设ID是不连续的:
select top 40 * from A except select top 30 * from A
或
select top 10 * from A where ID > (select max(ID) from A where ID in (select top 30 ID from A))
或
select top 10 * from A where ID not in (select top 30 ID from A)
本文提供了一种在SQL Server中获取表A中ID为31到40的记录的方法,即使ID不是连续的也能实现。文章给出了两种情况下的解决方案:ID连续与ID不连续,并提供了经过测试的SQL语句。
1028

被折叠的 条评论
为什么被折叠?



