大家好,这是我的SQL语句,
SQL> select count(*) from testresult t where t.customer_id=94 and t.test_id=(select e.exam_id from exam e where e.end_time is null and rownum=1 and e.customer_id=94 order by start_time desc);总提示这个错误ERROR 位于第 1 行:
ORA-00907: 缺少右括号为什么???请大侠指教~~

解决方案 »

  1.   

    问题出在你的ORDER by上面.
      

  2.   

    去掉order by不就行了
    或者把order by start_time desc改成order by e.start_time desc试试
      

  3.   

    改成
    select count(*) from testresult t where t.customer_id=94 and t.test_id in (select e.exam_id from exam e where e.end_time is null and rownum=1 and e.customer_id=94 order by start_time desc);
      

  4.   

    谢谢pjuner() ,但是我试过你的2个放都是老样子,呵呵。不用order by 确实可以正常运行,但是我确实需要这个排序呀。请问为什么不能用order by 呢?
      

  5.   

    用order by 的作用是什么呢,另外你的t.test_id = 是只有一行,还是多行呢
    如果是单行的话就后面用select top 1 ......最好前面用in而不是等号
      

  6.   

    楼上有没搞错?这是oralce开发社区啊,哪来的select top??而且语句里有一个rownum=1,表示只有1条记录呀
      

  7.   

    select 
      count(*) 
    from 
       testresult t,
         (select 
            e.exam_id 
          from exam e 
          where 
             e.end_time is null 
         and rownum=1 
         and e.customer_id=94 
         order by start_time desc
         ) tmp 
    where 
        t.customer_id=94 
    and t.test_id= tmp.exam_id 
    /
      

  8.   

    运行结果:
    SQL> /  COUNT(*)
    ----------
             0
      

  9.   

    呵呵,caiguoyuan(炽天使),真是服你了,语句正确且不说,结果你怎么能得到呢?呵呵,,神人~