0

我有 2 个工作查询我想加入一个并生成 4 列,如下所示。有人可以帮忙吗?我认为 Union 会起作用,但似乎将 Volume Loaded 和 Volume Useable 添加到同一列中。

供应商 | SCP | 卷加载 | 可用容量
================================================

查询一:

SELECT sd.dataprovider AS Supplier, LEFT(sd.SourceCodePrefix, 2) AS SCP, COUNT(*) AS `Volume Loaded` FROM sourcedescription sd
JOIN customerafterimport cai
ON cai.`SourceCode` = sd.`SourceCodePrefix`
JOIN importcustomerpack icp
ON icp.`Id` = cai.`ImportPackId`
GROUP BY LEFT(sd.SourceCodePrefix, 2)

查询 2:

SELECT sd.dataprovider AS Supplier, LEFT(sd.SourceCodePrefix, 2) AS SCP,  COUNT(*) AS `Volume Useable` FROM sourcedescription sd
JOIN customerafterimport cai
ON cai.`SourceCode` = sd.`SourceCodePrefix`
JOIN importcustomerpack icp
ON icp.`Id` = cai.`ImportPackId`
WHERE isRemovedValidate IS NULL
AND IsRemovedSuppress IS NULL 
AND IsRemovedDeDup IS NULL
AND IsRemovedCleanse IS NULL 
AND IsRemovedPostcodeCleanse IS NULL 
AND IsRemovedSuppressTPS IS NULL
AND IsRemovedCleanseProfanity IS NULL
GROUP BY LEFT(sd.SourceCodePrefix, 2)
4

1 回答 1

0
SELECT q1.Supplier, q1.SCP, `Volume Loaded`, `Volume Useable`
  FROM ( query 1 ) as q1
  JOIN ( query 2 ) as q2
    ON q1.Supplier = q2.Supplier AND q1.SCP = q2.SCP
于 2013-10-18T19:45:15.780 回答