我已经尝试了我能想到的每一个连接,但无法解决:(
我有两张table
表x和表y
两个表都包含物料代码和数量
我要找的是能帮我比较的东西
理想情况下,我想看看这样的东西,有可能吗?
示例数据表x
+-----------+-----+
| Item Code | QTY |
+-----------+-----+
| A | 1 |
+-----------+-----+
| B | 2 |
+-----------+-----+
| C | 3 |
+-----------+-----+
表y
+-----------+-----+
| Item Code | QTY |
+-----------+-----+
| A | 1 |
+-----------+-----+
| D | 2 |
+-----------+-----+
| E | 3 |
+-----------+-----+
最终结果我想看到这样的东西:
+-----------+-------------+-------------+
| Item Code | TABLE X QTY | Table Y QTY |
+-----------+-------------+-------------+
| A | 1 | 1 |
+-----------+-------------+-------------+
| B | 2 | 0 |
+-----------+-------------+-------------+
| C | 3 | 0 |
+-----------+-------------+-------------+
| D | 0 | 2 |
+-----------+-------------+-------------+
| E | 0 | 3 |
+-----------+-------------+-------------+
这可能是plz的帮助吗
2条答案
按热度按时间d8tt03nd1#
这看起来像一个
full join
```select coalesce(x.item, y.item) as item,
coalesce(x.qty, 0) as x_qty, coalesce(y.qty, 0) as y_qty
from x full join
y
on x.item = y.item
7ajki6be2#
尝试使用
full outer join
...