提取第8行记录到第16条记录的sql语句怎么写?
如题
------解决方案--------------------加一個id
alter table t
add id int identity(1,1)
select * from t where id between 8 and 16
------解决方案--------------------好快,正解
------解决方案--------------------select top 9 tid
from (select top 16 tid from table) t order by t.tid desc
------解决方案--------------------原表结构不动的情况下 加在临时表中
select identity(int,1,1) as rowNum,* into #t from 表名
select * from #t where rowNum between 8 and 16
------解决方案--------------------select top 9 * from (select top 16 * from table order by id) t order by id desc
or:
select top 9 * from table where id not in (select top 7 id from table order by id) order by id
------解决方案--------------------方法一
select top 8 * from table where id in(select top 16 id from table order by id desc)
方法二
select identity(int,1,1) as id,* into #t from 表名
select * from #t where rowNum between 8 and 16
------解决方案--------------------方法一
select * from (
select top 8 * from table where id in(select top 16 id from table order by id desc)
order by id desc)
order by id
方法二
select top 8 * from table where id not in (select top 8 id from table order by id )
order by id