首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

|M| 求SQL查询语句,查询出表中第11条到20条的记录解决思路

2011-12-28 
|M| 求SQL查询语句,查询出表中第11条到20条的记录如select*fromtab1现在要求是select11to20fromtab这样的

|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)

热点排行