如果我有 3 个如下表:
Table A:
Item Start_QTY
A 100
B 100
表 B:
Item Purchase_QTY
A 10
C 20
表 C:
Item End_QTY
A 90
B 10
C 10
如何加入 2 个表以获得以下结果:
Item Start_QTY Purchase_QTY End_QTY
A 100 10 90
B 100 NULL 10
C NULL 20 10
如果我执行以下操作:
Select COALESCE(a.item, b.item, c.item) as item, a.start_QTY, b.purchase_QTY, c.End_QTY from
A as a
full outer join
B as b
on a.item = b.item
full outer join
C as c
on a.item = c.item
我得到以下信息:
A 100 10 90
B 100 NULL 10
C NULL 20 NULL
C NULL NULL 10