我有两个查询,如下所示。查询选择相同的表,但具有不同的条件和列数。我无法解决如何组合这些;有什么办法吗?
第一个查询是:
SELECT b.centerBranchNumber,
b.countryCode,
a.type,
SUM(DECODE(a.status, 1, 1, 0)) filled
FROM tableA a,
tableB b
WHERE a.branchCode = b.branchCode
AND a.registerNumber IN (SELECT c.registerNumber
FROM tableC c
WHERE c.registerDate <= '01.02.2013'
AND c.state = 'A'
AND c.contractState != 2)
GROUP BY b.centerBranchNumber,
b.countryCode,
a.type;
结果如下所示:
BranchNumber CountryCode Type Filled
1452 USA 0 5
1452 USA 2 8
1452 USA 1 16
7854 GER 0 10
7854 GER 1 3
第二个查询是:
SELECT b.centerBranchNumber,
b.countryCode,
a.type,
SUM(DECODE(a.status, 0, 1, 0)) free,
SUM(DECODE(a.status, 2, 1, 0)) damaged
FROM tableA a,
tableB b
WHERE a.kks_kayitdrm = 'A'
AND a.branchCode = b.branchCode
AND a.recordDate <= '01.02.2013'
GROUP BY b.centerBranchNumber,
a.type,
b.countryCode;
结果是:
BranchNumber CountryCode Type Free Damage
1452 USA 0 5 2
1452 USA 2 8 1
1452 USA 1 16 5
7854 GER 0 10 9
7854 GER 1 3 16
如果我结合起来,我希望得到如下结果:
BranchNumber CountryCode Type Filled Free Damage
1452 USA 0 1 5 2
1452 USA 2 2 8 1
1452 USA 1 65 16 5
7854 GER 0 7 10 9
7854 GER 1 45 3 16