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

zyciis229 2007-04-30 11:17:16
如select * from tab1
现在要求是
select 11 to 20 from tab 这样的

谢谢
...全文
567 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
anan221 2007-05-01
  • 打赏
  • 举报
回复
Select top 10 From tab1 where id not in
(Select top 10 from tab1 order by id)
hertcloud 2007-05-01
  • 打赏
  • 举报
回复
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
shadow841112 2007-04-30
  • 打赏
  • 举报
回复
select top 5 * from (select top 15 * from table order by id asc) table_别名 order by id desc
hertcloud 2007-04-30
  • 打赏
  • 举报
回复
not in在 几十万 数据 的情况 还可以...

top max 可以 应付 千万级的分页.



但是楼主要注意点 这两种分页 模式下 你的 排序 主键 都必须的 不重复值的.

如果重复 那么sql 2005以前 需要 临时表 解决
sql 2005 有 row_number 很好用
hertcloud 2007-04-30
  • 打赏
  • 举报
回复
这里有 这两种 形式的 分页通用过程
http://blog.csdn.net/hertcloud/category/281167.aspx

zyciis229 2007-04-30
  • 打赏
  • 举报
回复
select top 5 * from (select top 15 * from table order by id asc) table_别名 order by id desc

这里面有对id 进行排序
要是我本来要查询的数据id是很乱的而不是顺的 就不行了

selecct top 5 * from table where id not in (select top 10 id from table order by id asc) order by id asc

这条看起来还有点可行但是要是
selecct top 5 * from table where id not in (select top 10000 id from table order by id asc) order by id asc
这样要对10000条数据进行比较会不会太慢了

hertcloud 2007-04-30
  • 打赏
  • 举报
回复
对于 GUID只能 使用上面的形式
对于int类型 可以使用 效率更好的.

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
hertcloud 2007-04-30
  • 打赏
  • 举报
回复
select top 10 [LogID], [UserID], [TrueName] from TB_ActiveLog where LogID not in(select top 10 LogID from TB_ActiveLog order by LogID DESC ) order by LogID DESC
amandag 2007-04-30
  • 打赏
  • 举报
回复
求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
================================================

这个是个比较经典的案例了
ly_0205 2007-04-30
  • 打赏
  • 举报
回复
sql server 这样: 其它数据库可能有支持你写的那种方式

select top 20 identity(int,1,1) lineSN,* into # from tab1
select * from # where lineSN > 10
drop table #
RexZheng 2007-04-30
  • 打赏
  • 举报
回复
选择从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
最后一只恐龙 2007-04-30
  • 打赏
  • 举报
回复
求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都忘了
最后一只恐龙 2007-04-30
  • 打赏
  • 举报
回复
按id排序
Select top 10 From tab1 where id not in
(Select top 10 from tab1 order by id)
order by id

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧