我想选择一个不在 ('DC01','5000') 中但在 SUM 大于 3 的 ('1003','1039','1012') 中的 SKU。我打算取回零记录,因为 SKU '000000001041106003' 在 '1003' 中,StockOnHand 大于 3,但 StoreID 为 'DC01',但返回 SKU 值 '000000001041106003'。该 SKU 的 StoreID 为“DC01”和“1003”。
我需要做什么才能获得预期的结果?
productName SKU StoreId StockOnHand webenabled
.Speedo Yarn 000000001041106001 1003 1 1
.Speedo Yarn 000000001041106002 1003 3 1
.Speedo Yarn 000000001041106003 1003 4 1
.Speedo Yarn 000000001041106003 DC01 0 1
SELECT DISTINCT(SKU)
FROM etlStoreAssortment
WHERE StoreId NOT IN ('DC01','5000')
AND StoreId IN ('1003','1039','1012') GROUP BY SKU HAVING SUM(StockOnHand) > 3