我執行子查詢來識別我想要的行排除。那些是在列b上有NULL值的那些。 Parent Supplier Name
。這工作正常,直到我試圖得到其餘的總和(b。Spend Value in LC
)。LEFT JOIN和IS NULL工作但不是SUM功能
SELECT a.`BW Parent Number` , a.`Vendor Name` , b.`Parent Supplier Name` , sum(b.`Spend Value in LC`) as sum
FROM scrubs a
LEFT JOIN (
SELECT `Child Supplier ID` , `Parent Supplier Name` , `Spend Value in LC`
FROM pdwspend
WHERE `BU ID` = 'BU_1'
AND `version` LIKE '%FINAL%'
)b ON a.`BW Parent Number` = b.`Child Supplier ID`
WHERE a.`year` =2014
AND b.`Parent Supplier Name` IS NULL
GROUP BY a.`BW Parent Number`
ORDER BY sum(b.`Spend Value in LC`) DESC
結果的願望有這樣的結構:
`BW Parent Number` | `Vendor Name` | `Parent Supplier Name` | sum
BW0001 XYC NULL 300,000
.....
.....
現在我得到這個爲所有不包含在子查詢行:
`BW Parent Number` | `Vendor Name` | `Parent Supplier Name` | sum
BW0001 XYC NULL NULL
....
....
謝謝!
顯示一些示例數據。 – Laurence 2014-09-21 22:24:31
你可以試着'Sum(Coalesce(b。\'花在LC \'中的值,0))' – Siyual 2014-09-21 23:03:06