这是样本输出如何摆脱列中的冗余值?
让我解释一下这是怎么回事:
查询返回的所有发票,每年的#与参与发票产品 一起。
如您所见,我们在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