表a
no
111 
112
113表b
no  year count detail
111 2009 1     hello
111 2010 3     nice113 2010 2从a,b取数据,b取最大年份数据,生成结果如下,请问怎么操作呢:表C
no   count  detail
111  3      nice
112  0
113  2

解决方案 »

  1.   


    select aa.no,nvl(bb.cnt,0),bb.detail
    from a aa,b bb
    where aa.no=bb.no(+)
      and not exists(select 1 from b tb where bb.no=tb.no
                                          and bb.year<tb.year)
       NO NVL(BB.CNT,0) DETAI
    ----- ------------- -----
      112             0
      111             3 nice
      113             2
      

  2.   

    太厉害 哈哈 
    我就是想取max的记录,有的记录又 not exists 正不知道怎么判断呢