select  S.STATION_NAME  AS    station_name,  
(select  E.ID    from  OM_ELEC_DETAIL  E    where  S.ID=E.BASE_ID and rownum<2 order  by  E.ID  desc)  AS  chargeId  
   
 from  OM_BASE_STATION S     
 
在ORacle 中运行 报错:缺少右括号;请高手帮我解决,本人很少写ORACLE语句。解决为谢!!! 

解决方案 »

  1.   

    子句的order by没有用去掉,改为:
    select  S.STATION_NAME  AS    station_name,  
    (select  E.ID    from  OM_ELEC_DETAIL  E    where  S.ID=E.BASE_ID and rownum=1 )  AS  chargeId     
     from  OM_BASE_STATION S   试试
      

  2.   

    --改为
    Select  S.STATION_NAME  AS    station_name,   
      ( Select  E.ID from  OM_ELEC_DETAIL  E    
      where  S.ID=E.BASE_ID and rownum<2 )  AS  chargeId 
     from  OM_BASE_STATION S  order by chargeId.ID  desc
      

  3.   

    Select  S.STATION_NAME  AS    station_name,   
      ( Select  E.ID from  OM_ELEC_DETAIL  E    
        where  S.ID=E.BASE_ID and rownum<2 )  AS  chargeId,
      ( Select  E.ADDR from  OM_ELEC_DETAIL  E    
         where  S.ID=E.BASE_ID and rownum<2 )  AS  addr,
         from  OM_BASE_STATION S  order by chargeId,addr  desc大哥你的那种方法可以,但是我还要加多个字段就不可行,帮帮忙,搞定给你100分,我在等待你的回复。
      

  4.   

    我不是要分的,很少像楼主这样写sql:
    -----------------------Select  S.STATION_NAME  AS    station_name,   
      ( Select  E.ID from  OM_ELEC_DETAIL  E    
        where  S.ID=E.BASE_ID and rownum<2 )  AS  chargeId,
      ( Select  E.ADDR from  OM_ELEC_DETAIL  E    
         where  S.ID=E.BASE_ID and rownum<2 )  AS  addr,
         from  OM_BASE_STATION S  order by chargeId,addr  desc
    -----------------------
    你的那种方法可以,但是我还要加多个字段就不可行?我调试了一下这样的sql:
    select s.xh,
           s.xm,
           (select t1.ski_niuke_cd
              from abc121313_0 t1
             where S.xh = t1.ski_niuke_cd
               and rownum < 2) as dd,
           (select t2.ord
              from abc121313_0 t2
             where S.xh = t2.ski_niuke_cd
               and rownum < 2) as ddd,
           s.num
      from aa_test s
     order by dd, ddd desc
    可以执行的,你把错误提示写出来!