表A 中有一条数据 
ID      code    year    money 
20858 01 2006 10表B中有5条数据
cod
 01
 02
 03
 04
 05
我要查询得到结果如下:
  ID      code   year    money 
 20858     01     2006   10
 20858     02     2006   0
 20858     03     2006   0
 20858     04     2006   0
 20858     05     2006   0请高手们赐教! 

解决方案 »

  1.   

    select nvl(id,(select  id from a where rownum <2 )),B.code,nvl(year,(select  year from a where rownum <2)),nvl(money,0) 
    from A right join t on A.code=B.code
      

  2.   

    select c.id,c.code,c.year,nvl(a.money,0) from (select a.id,a.year,b.code from a,b) c,a
    where c.id=a.id(+)
      

  3.   

    select a.id, b.cod, a.year, decode(a.code, b.cod, a.money, 0) money
      from a, b;
      

  4.   

    上面这个我试了, 可以. 只是觉得楼主, 为什么字段名不统一, 一会儿code, 一会儿cod. 
    这样写起SQL怪怪的.