|M| 求SQL查询语句,查询出表中第11条到20条的记录
如select * from tab1
现在要求是
select 11 to 20 from tab 这样的
谢谢
------解决方案--------------------按id排序
Select top 10 From tab1 where id not in
(Select top 10 from tab1 order by id)
order by id
------解决方案--------------------求m~n条
Select top (n-m+1) * From tab1 where id not in
(Select top m id from tab1 order by id)
order by id
上个帖子top 10后面把*和id都忘了
------解决方案--------------------选择从10到15的记录
select top 5 * from (select top 15 * from table order by id asc) table_别名 order by id desc
or
selecct top 5 * from table where id not in (select top 10 id from table order by id asc) order by id asc
------解决方案--------------------sql server 这样: 其它数据库可能有支持你写的那种方式
select top 20 identity(int,1,1) lineSN,* into # from tab1
select * from # where lineSN > 10
drop table #
------解决方案--------------------求m~n条
Select top (n-m+1) * From tab1 where id not in
(Select top m id from tab1 order by id)
order by id
================================================
这个是个比较经典的案例了
------解决方案--------------------select top 5 * from (select top 15 * from table order by id asc) table_别名 order by id desc
------解决方案--------------------select top 10 [LogID], [UserID] from TB_ActiveLog where LogID <
(select min(LogID) from (select top 10 LogID from TB_ActiveLog order by LogID DESC ) AS TBMinID) order by LogID DESC
这个是数据 倒排的时候 从第一条开始
select top 10 [LogID], [UserID] from TB_ActiveLog where LogID >
(select max(LogID) from (select top 10 LogID from TB_ActiveLog order by LogID ASC ) AS TBMinID) order by LogID ASC
------解决方案--------------------Select top 10 From tab1 where id not in
(Select top 10 from tab1 order by id)