日期:2014-05-18  浏览次数:20545 次

关于sql语句的问题
在数据库中现有如下数据:
A表:
stockcode         qty1           amount1
  A                         10               100
  B                           5                 50
  C                         20                 60
  D                         100             600

B表:
stockcode         qty2           amount2
  A                         10               100
  B                           5                 50
  E                         20                 90

现在我想将这两个表进行合并,形成如下形式,
stockcode         qty1           amount1         qty2           amount2    
  A                         10               100                 10               100
  B                           5                 50                   5                 50
  C                         20                 60                   0                   0
  D                         100             600                   0                   0
  E                         0                   0                   20                 90

在没有数据的栏目中输入0,请问用sql语句要怎么实现啊,
请高手不吝赐教,感激不尽。

------解决方案--------------------
select
isnull(A.stockcode,B.stockcode) as stockcode,
isnull(A.qty1 ,0) as qty1 ,
isnull(A.amount1,0) as amount1,
isnull(B.qty1 ,0) as qty2 ,
isnull(B.amount1,0) as amount2
from
A
full outer join
B
on
A.stockcode=B.stockcode
------解决方案--------------------
学习学习
------解决方案--------------------
高手