如何在SQL Server中查询指定行

mnwind 2002-10-18 03:09:30
如何在SQL Server中查询指定行.
例如这样一个表 info,有三个字段: id, name, date
想要查询按照date字段desc排序的第10个记录,如何操作?
想要查询按照date字段desc排序的第11-20个记录,又如何操作?
...全文
148 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
leimin 2002-10-18
  • 打赏
  • 举报
回复
date为表中的关键字段,n是截取的次数,10 为每次截取的记录数试试看,我这里测试通过。
select top 10 * from table
where date not in(select top 10*(n-1) key from table)
hillhx 2002-10-18
  • 打赏
  • 举报
回复
select top 10 *
from (select top 20 * from table6 order by id) tt
order by id desc

取一个就更简单了:),把10该成1就等于取第20笔
warton 2002-10-18
  • 打赏
  • 举报
回复
说错了,应该是一个自增的整型id
warton 2002-10-18
  • 打赏
  • 举报
回复
用一个唯一键标明每一个字段,select * from table1 where id<20 and id>10;
mnwind 2002-10-18
  • 打赏
  • 举报
回复
还有没有效率高一点的呢
xiaonan 2002-10-18
  • 打赏
  • 举报
回复
select * from info
where id not in
(select top 9 id from info order by date desc)
and id in
(select top 10 id form info order by date desc)

第二个,把9改成10,10改成20就可以了.
mnwind 2002-10-18
  • 打赏
  • 举报
回复
查询出来以前也有好多这样的帖子的,但是看不了了;(

34,873

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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