SQL语句编译后提示缺失右括号

jobli101010 2010-04-22 07:23:52
select TBL_TOPIC.* from TBL_TOPIC
where boardId=1
and topicId not in (select topicId from TBL_TOPIC where boardId=1 and rownum<=1 order by publishTime)
and rownum <20 order by publishTime
提示缺失右括号
把子查询提取查询结果写入not in()中没有问题
select topicId from TBL_TOPIC where boardId=1 and rownum<=1 order by publishTime

查询结果1,2

select TBL_TOPIC.* from TBL_TOPIC
where boardId=1
and topicId not in (1,2)
and rownum <20 order by publishTime
正确

请问怎么回事啊?
...全文
758 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
shancao 2010-04-25
  • 打赏
  • 举报
回复
这个sql即使能运行,效率也会比较低,不知道这个sql是干吗用的?看上去有点莫名其妙,可以把你的用途说一下。
清风智语 2010-04-24
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 tangren 的回复:]

就语句本身来说,没有问题啊,不过有order by子句使用rownum得不到你想要的,
还有,如果rownum<=1,可以不使用not in了。
[/Quote]
up
心中的彩虹 2010-04-24
  • 打赏
  • 举报
回复
select TBL_TOPIC.* from TBL_TOPIC
where boardId=1
and topicId not in (select topicId from TBL_TOPIC where boardId=1 and rownum<=1 order by publishTime)
and rownum <20 order by publishTime
--楼上所说不能在子查询中使用order by语句


--本人看了你的语句的意思写了下面的语句.
select * from (select TBL_TOPIC.* ,rownumn rn from TBL_TOPIC
where boardId=1 and rownum <20
order by publishTime) a
where rn between 2 and 19
JobyGuo 2010-04-24
  • 打赏
  • 举报
回复
子查询执行操作时应该遵循的规则,lz去看一下,其中一条是子查询不能包含order by 子句
JobyGuo 2010-04-24
  • 打赏
  • 举报
回复
子查询不能包含order by 子句
ywgoal 2010-04-23
  • 打赏
  • 举报
回复
rownum < 1 了,,还order by啊
tangren 2010-04-22
  • 打赏
  • 举报
回复
就语句本身来说,没有问题啊,不过有order by子句使用rownum得不到你想要的,
还有,如果rownum<=1,可以不使用not in了。
iqlife 2010-04-22
  • 打赏
  • 举报
回复
把子查询提取查询结果写入not in()中没有问题
select topicId from TBL_TOPIC where boardId=1 and rownum<=1 order by publishTime
去掉order by publishTime就可以了

17,140

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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