我得到两个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'值为零,或者两者都是非会发生什么-零? –