select a.xlid,
       b.zdid qszid,
       b.zdmc qszmc,
       b.zddz qszdz,
       c.zdid zzzid,
       c.zdmc zzzmc,
       c.zddz zzzdz
  from (select xlid, min(to_number(zdsxh)) xh1, max(to_number(zdsxh)) xh2
          from jjwgps_t_zdlyb
         where szgjfx = 0
         group by xlid) a,
       (select xlid, zdid, zdsxh, zdmc, zddz
          from jjwgps_t_zdlyb
         where szgjfx = 0) b
 where a.xlid = b.xlid
   and (a.xh1 = b.zdsxh or a.xh2 = b.zdsxh)

解决方案 »

  1.   

    试试select xlid,
    max(zdid)keep(dense_rank first order by zdsxh)qszid,
    max(zdmc )keep(dense_rank first order by zdsxh)qszmc,
    max(zddz )keep(dense_rank first order by zdsxh)qszdz ,
    max(zdid)keep(dense_rank last order by zdsxh)zzzid,
    max(zdmc )keep(dense_rank last order by zdsxh)zzzmc,
    max(zddz )keep(dense_rank last order by zdsxh)zzzdz 
    from  jjwgps_t_zdlyb where szgjfx=0  group by xlid;
      

  2.   

    @zlloct
    ORA-00904: "C"."ZDDZ": invalid identifier
      

  3.   

    只给出SQL肯定无法优化为最优,最好先看一下执行计划,因为现在oracle大部分用都是CBO。
      

  4.   

    谢谢 wildwave 
    已经解决,你真厉害!