我有关于访问的工会问题。
我有表MyCount
S | A | M | Q
=============
1 |10 |111| 4
1 |10 |222| 5
1 |10 |333| 9
1 |20 |444|10
我有表目录
S | A | M |
=============
1 |10 |111|
1 |10 |222|
1 |10 |333|
1 |10 |444|
1 |10 |555|
1 |20 |999|
1 |20 |888|
1 |20 |777|
我需要MyCount中的所有数据和目录 - 但是如果数据在MyCount上
不在目录中,它将带有Qty = 0
我需要联合查询,即resault将如下所示:
S | A | M | Q
=============
1 |10 |111| 4
1 |10 |222| 5
1 |10 |333| 9
1 |10 |444| 0
1 |10 |555| 0
1 |20 |999|10
1 |20 |888| 0
1 |20 |777| 0
答案 0 :(得分:1)
您可以使用union all
:
select s, a, m, q
from mycount
union all
select s, a, m, 0
from catalog as c
where not exists (select 1
from mycount as mc
where mc.s = c.s and mc.a = c.a and mc.m = c.m
);