【发布时间】:2014-09-21 22:19:44
【问题描述】:
我执行子查询来识别我想要排除的行。这些是在 b.Parent Supplier Name 列上具有 NULL 值的那些。在我尝试得到其余部分的总和(b.Spend Value in LC)之前,这很好用。
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
....
....
谢谢!
【问题讨论】:
-
显示一些示例数据。
-
你可以试试
Sum(Coalesce(b.`Spend Value in LC`, 0))
标签: mysql sql sum left-join isnull