tab1
id name total1
1  a     100
2  d     20
3  c     30
4  b     40
5  e     60
tab2
id name total2
1  a    100
2  p    1000
3  o    60
4  c    80
5  e    40结果
id name total1 total2
1  a    100     100
2  c    30      80
3  e    60      40
4  d    100
5  b    40
6  p           1000
7  o            60请教高手,用什么语句呀??先谢谢了

解决方案 »

  1.   


    select ROWNUM AS ID ,tab1.NAME,tab1.total1, tab2.total2 FROM TAB1 FULL JOIN TAB2 ON 
    TAB1.NAME=TAB2.NAME 
      

  2.   

    仔细研究了一下,发现你这个没我想的那么简单。
    更正一下,通过测试select ROWNUM AS ID ,a.* from (
    select tab1.NAME,tab1.total1, tab2.total2 FROM TAB1 FULL JOIN TAB2 ON 
    TAB1.NAME=TAB2.NAME 
     union
    select tab2.NAME,tab1.total1, tab2.total2 FROM TAB1 FULL JOIN TAB2 ON 
    TAB1.NAME=TAB2.NAME) a
    where a.name is not null 
      

  3.   

    select a.name,a.total1,b.total2 from tab1 a ,tab2 b where tab1.name=tab2.name(+)
    union
    select b.name,a.total1,b.total2 from tab1 a, tab2 b where tab1.name(+)=tab2.name