有 两个 表  PJ3500,PJ3510
PJ3500的主键是 年度,种别
pj3510的主键是  年度,种别,变更回数要查询的数据是 PJ3500里存在,PJ3510里变更次数最大的记录条数。如果PJ3510里不存在对应数据的话,也能检索出来。

解决方案 »

  1.   

    select max(变更回数) from (select t1.年度,t1.种别,t2.变更回数 from PJ3500 t1 left join pj3510 t2 on
     t1.年度=t2.年度 and t1.种别=t2.种别)
      

  2.   

    select count(*) from PJ3500 t1 left join pj3510 t2 on 
    t1.年度=t2.年度 and t1.种别=t2.种别 where t2.变更回数=(select max(变更回数) from pj3510)
      

  3.   

    select t3.* from (select t2.* 
                        from pj3510 t1, pj3510 t2 
                       where t1.年度 = t2.年度
                           and t1.种别 = t2.种别
                          order by t2.变更回数) t3
               where rownum = 1;
      

  4.   

    select a.* from PJ3510 a,PJ3500 b where a.种别=b.种别(+) and a.年度=b.年度(+)
      

  5.   

    select max(c) from ( select  a,b,c from p1,p2 where p1.a=p2.a and p1.b=p2.b)
     
      

  6.   

    select s.*,t.times from times1 s ,( select w.year_1,w.type_1 ,max(w.change_times) as times from times2 w group by w.year_1, w.type_1) t
     where s.year_1 = t.year_1(+)
     and s.type_1 = t.type_1(+)
     
      

  7.   

    select s.*,t.times from times1 s ,( select w.year_1,w.type_1 ,max(w.change_times) as times from times2 w group by w.year_1, w.type_1) t 
    where s.year_1 = t.year_1(+) 
    and s.type_1 = t.type_1(+) 
    引用了 (+) 后 ,max(w.change_times) as times 就失效了 。该怎么办呢 
      

  8.   

    用外连接后,虽然写了max,但实际上把 所有的记录都取出来了。
      

  9.   

    这位大哥理解了我的意思,可惜这个 sql语句达不到 预期的效果,因为max和外连接 写一起,max就失效了。 
      

  10.   

    我在Oracle 10g上,测试过的,结果没有问题的。如果PJ3510里不存在对应数据的话,也能检索出来。 
    那它对应的changtimes应该是什么,现在是空的。