日期:2014-05-18  浏览次数:20398 次

下面这条Sql语句该怎样写呢?( 注意:自动增长的主键ID是不连续的。)
写出一条Sql语句:   取出表A中第31行到第40行的记录(SQLServer数据库,   以自动增长的ID作为主键,     注意:ID可能不是连续的。)

------解决方案--------------------
select TOP 10 * from A
where ID not in
(
select TOP 30 ID from A order by ID
)
order by ID
------解决方案--------------------
create table T(ID int)
insert T select 2
insert T select 3
insert T select 6
insert T select 7
insert T select 10

insert T select 12
insert T select 14
insert T select 15
insert T select 16
insert T select 23

--取3-5行
select * from T tmp
where (select count(*) from T where ID <=tmp.ID)between 3 and 5

--result
ID
-----------
6
7
10

(3 row(s) affected)