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,2select TBL_TOPIC.* from TBL_TOPIC 
       where boardId=1  
       and topicId not in (1,2)  
       and rownum <20 order by publishTime
正确请问怎么回事啊?

解决方案 »

  1.   

    把子查询提取查询结果写入not in()中没有问题
    select topicId from TBL_TOPIC where boardId=1 and rownum<=1 order by publishTime
    去掉order by publishTime就可以了
      

  2.   

    就语句本身来说,没有问题啊,不过有order by子句使用rownum得不到你想要的,
    还有,如果rownum<=1,可以不使用not in了。
      

  3.   

    rownum < 1 了,,还order by啊
      

  4.   

    子查询不能包含order by 子句
      

  5.   

    子查询执行操作时应该遵循的规则,lz去看一下,其中一条是子查询不能包含order by 子句
      

  6.   

    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
      

  7.   

    这个sql即使能运行,效率也会比较低,不知道这个sql是干吗用的?看上去有点莫名其妙,可以把你的用途说一下。