Reputation: 47
I am trying to write an SQL statement that will calculate the total value of a purchase order.
Example time!
SELECT PO_Number, LineItem, Quantity, Cost
FROM POs
Say on PO_Number=484
there are 2 units of LineItem-1
at $2 each. There are also 3 units of LineItem-2
at $5 each. Is there a way to output $19? (2 + 2 + 3 + 3 + 3 = 19)
Upvotes: 0
Views: 44
Reputation: 81
Or...
SELECT PO_Number, SUM(Quantity*Cost) GROUP BY PO_Number;
Upvotes: 1
Reputation: 125945
SELECT SUM(Quantity*Cost) WHERE PO_Number = 484;
UPDATE
If you want to show the totals for multiple purchase orders, you need to "group" your results by purchase order:
SELECT SUM(Quantity*Cost)
WHERE PO_Number IN (484,485,486) -- if you want specified ones only, omit for all
GROUP BY PO_Number;
Upvotes: 4