我得到兩個select查詢的UNION,其中一個查詢表是一個臨時表以確保輸出記錄(所以臨時表具有每個日期的預期輸出但以0出售列的默認值根據2列過濾來自UNION結果的重複項
一個例子輸出結果會是這樣的:
ProductID | Product Desc | TransactionDate | Sale
1011021 | SD DOG | 2017-01-07 | 0
1011021 | SD DOG | 2017-01-07 | $17
1011021 | SD DOG | 2017-01-14 | 0
1011021 | SD DOG | 2017-01-14 | $15
1011021 | SD DOG | 2017-01-21 | $21
1011021 | SD DOG | 2017-01-28 | 0
1011021 | SD DOG | 2017-01-28 | $21
聯盟消除基於行的複製,我怎樣才能讓它在基於產品ID刪除重複和transactionDate列,刪除銷售額爲0的重複項?
--query下面
SELECT transactionProducts.productID, products.productDesc, sum(salePrice) as Sale, transactionDate
FROM products LEFT JOIN transactionProducts on products.productID = transactionProducts.productID
LEFT JOIN transactions ON transactionProducts.transactionID = transactions.transactionID
LEFT JOIN productCategory on productCategory.productID = products.productID
LEFT JOIN categories on categories.categoryID = productCategory.categoryID
WHERE (transactionProducts.productID='123' AND transactions.transactionDate='2017-01-12'
Group by transactionProducts.productID, transactionDate
UNION select * from "temptable" group by productID, productDesc, Sale, transactionDate
ORDER BY transactionDate
如果兩個'Sale'值爲零,或者兩者都是非會發生什麼-零? –