查询第10-20条记录怎么写?

ancestor1 2010-03-04 04:13:09

select top 20 * from news where (id not in(select top 10 * from news)) order by id asc

我这么写的
但是有错
消息 116,级别 16,状态 1,第 1 行
当没有用 EXISTS 引入子查询时,在选择列表中只能指定一个表达式。

要怎么写啊?
...全文
481 27 打赏 收藏 转发到动态 举报
写回复
用AI写文章
27 条回复
切换为时间正序
请发表友善的回复…
发表回复
keyyi 2010-03-05
  • 打赏
  • 举报
回复

select top 11 * from (select top 20* from news order by id asc) B order by B.id desc
daishaodong 2010-03-05
  • 打赏
  • 举报
回复
10到20,如果含第10的话,可是11个记录哟,

select top 11 * from news where id not in (select top 9 id from news ) order by id
zaytsing 2010-03-05
  • 打赏
  • 举报
回复

SELECT * from (SELECT TOP 20* FROM news )a WHERE a.ID NOT IN(SELECT TOP 10 ID FROM news ) order by ID asc
select top 20 * from news where (id not in(select top 10 * from news)) order by id asc


这样就好了。。你先把前20 条搞成临时表就好了。。再慢慢筛选。。你这句不行的,条件中括号的ID根本不知道哪里来。。即使括号去掉。。先后顺序也错了。。这样,只是先去掉头10条,再取下面的20条记录。。
itliyi 2010-03-05
  • 打赏
  • 举报
回复
select top 10 * from news where (id not in(select top 10 id from news)) order by id asc
薇薇 2010-03-05
  • 打赏
  • 举报
回复
select top 4 * from
(select * from score ) as a
order by score desc

if exists(select * from sysobjects where name='temp')
drop table temp
select identity(int,1,1) as id0,score into temp from score

select * from temp where id0>=4 and id0<=7

select * from score where identitycol between 4 and 7
薇薇 2010-03-05
  • 打赏
  • 举报
回复
select top 4 * from
(select * from score ) as a
order by score desc

if exists(select * from sysobjects where name='temp')
drop table temp
select identity(int,1,1) as id0,score into temp from score

select * from temp where id0>=4 and id0<=7

select * from score where identitycol between 4 and 7
shikaree2008 2010-03-05
  • 打赏
  • 举报
回复

select top 11 * from news where id not in
(select top 9 id from news )



--注意,你的10到20条数据的查询结果其实是11条结果!所以这里是top 11和9
microsofttyc 2010-03-05
  • 打赏
  • 举报
回复
select top 10 * from (select top 20 * from news order by id asc) b order by id desc
qq497525725 2010-03-05
  • 打赏
  • 举报
回复
mark 回复内容太短了!
GS1T74wjwpg 2010-03-04
  • 打赏
  • 举报
回复
查出top10中最大的值 和 top20中最大的值...between一下就行了
yjdxpv 2010-03-04
  • 打赏
  • 举报
回复
select * from 表名 where id(标识列) between 10 and 20 order by id(标识列)
andysun88 2010-03-04
  • 打赏
  • 举报
回复
select top 10 * 
from news
where
id not in(select top 10 [id] from news )
liaosunny 2010-03-04
  • 打赏
  • 举报
回复
不知道是不是经常有人出这种问题来考人呢.
winneryust 2010-03-04
  • 打赏
  • 举报
回复
如果是 sql 2005 可以用 楼上的方法。
iceswordman 2010-03-04
  • 打赏
  • 举报
回复
试试这个
select a.* from
(select ROW_NUMBER() OVER(ORDER BY id) as ID,Item_Number FROM BItemMaster) as a
where a.ID between 11 and 20
vivid0816 2010-03-04
  • 打赏
  • 举报
回复
这下是真学习了,做个记号在这里,留待以后使用
yhtapmys 2010-03-04
  • 打赏
  • 举报
回复

select top 20 *
from news
where
id not in(select top 10 [id] from news) order by [id] asc


去掉外围括号
把条件语句里的 * 号 改成 id

试一下
ancestor1 2010-03-04
  • 打赏
  • 举报
回复
引用 9 楼 pengwu311 的回复:
用子查询,先查询前20条,再查询10条不就行了。
select top 10 * from (select top 20 * from 表) t order by id desc

你没看到我写的吗?
我就是这么写的啊?
但是,出错了
没有用 EXISTS 引入子查询
你说怎么办?
小鹏 2010-03-04
  • 打赏
  • 举报
回复
用子查询,先查询前20条,再查询10条不就行了。
select top 10 * from (select top 20 * from 表) t order by id desc
cailee 2010-03-04
  • 打赏
  • 举报
回复
select * from
(
select top 10 *
from(
select top 20 *
from news
order by ID
)a
order by ID desc
)b
order by id
加载更多回复(7)

34,587

社区成员

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

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