這是樣本輸出如何擺脫列中的冗餘值?
讓我解釋一下這是怎麼回事:
查詢返回的所有發票,每年的#與參與發票產品 一起。
如您所見,我們在2010年有兩張發票...發票是30463和30516. 發票30463有4件商品,運費爲105.88美元。如您所見, 當我在報告級別計算總和時,會在導致問題的每件產品上重複發貨價格。發票#30463的4款產品的總運費價格爲 。無論發票內有多少種商品,我都希望每張發票 的每個運費只顯示一次。我怎樣才能實現它?
下面是該查詢:
SELECT
DATEPART(year, CustomerInvDetail.sentDate) AS "Year",
CustomerInvoice.cuInvoiceID,
Product.productName,
CustomerQuoteProducts.unitPrice,
CustomerQuoteProducts.qty,
CustomerQuoteProducts.qty * CustomerQuoteProducts.unitPrice AS "Price",
CustomerShipping.shippingPrice
FROM CustomerInvoice INNER JOIN CustomerInvDetail
ON CustomerInvoice.cuInvoiceID = CustomerInvDetail.cuInvoiceID
INNER JOIN CustomerQuote
ON CustomerQuote.customerQuoteID = CustomerInvoice.customerQuoteID
INNER JOIN CustomerQuoteProducts
ON CustomerQuoteProducts.customerQuoteID = CustomerQuote.customerQuoteID
INNER JOIN CustomerShipping
ON CustomerShipping.customerQuoteID = CustomerInvoice.customerQuoteID
INNER JOIN Customer
ON Customer.customerID = CustomerQuote.customerID
INNER JOIN Product
ON CustomerQuoteProducts.productID = Product.productID
WHERE (DATEPART(year, CustomerInvDetail.sentDate) BETWEEN 2001 AND 2022) AND (Customer.customerID = 500)
那麼,您的目標是讓發票的105.00只出現一次,而shippingPrice中剩餘的值顯示爲零? – Andrew 2010-09-24 15:21:19
你想顯示所有產品,但價格只有一次? 或者您只需要每張發票的價格和編號? – 2010-09-24 15:21:44
因此,對於任何給定的發票號碼,您希望運費僅在其中一行顯示?只要它只出現一次,哪一排不重要?發票的所有其他運輸價值將爲零? – LittleBobbyTables 2010-09-24 15:22:09