So, I currently have a SQL query that brings up a total amount for all orders for a specific customers. This equation is the following.
SUM((OrdIt.ItemPrice- OrdIt.DiscountAmount) * OrdIt.Quantity) As TotalAmount
However, I only want to display results where the initial ItemPrice
is OVER 500.
Where would I put OrdIt.ItemPrice > 500
?
CodePudding user response:
You could sum a CASE
expression which checks the price:
SUM((CASE WHEN OrdIt.ItemPrice > 500
THEN OrdIt.ItemPrice - OrdIt.DiscountAmount
ELSE 0 END) * OrdIt.Quantity)
CodePudding user response:
Can you not issue this SQL query?
SELECT SUM((OrdIt.ItemPrice - OrdIt.DiscountAmount) * OrdIt.Quantity) As
TotalAmount
FROM OrdIt
WHERE OrdIt.ItemPrice > 500;