MySQL Forums
Forum List  »  Newbie

Sum from a Derived Table
Posted by: Nicholas Soto
Date: January 17, 2013 04:18PM

I'm trying to create a second table from a derived table

So I have these 2 tables that I'm creating a table from
Table1 = Products
Table2 = order_details

I've created this script to get a table output the total cost for an order based on ID

select O.orderID, O.Quantity, P.UnitPrice, (O.Quantity*P.UnitPrice) as OrderCost
From Order_details as O
inner join Products as P
on O.ProductID = P.ProductID
group by P.ProductName
order by O.orderID; ;

Here an Exampe of my output

OrderID Quantity UnitPrice OrderCost
10248 5 8.99 44.95
10248 12 16.99 203.88
10248 10 6.99 69.90
10249 9 18.99 170.91
10249 40 27.99 1119.60
10250 15 16.99 254.85
10250 10 12.99 129.90

Id like to create a table from this that shows that TotalCost by OrderID

OrderID TotalCost
10248 318.73
10249 1290.51
10250 384.75

Suggestions?

Options: ReplyQuote


Subject
Written By
Posted
Sum from a Derived Table
January 17, 2013 04:18PM
January 17, 2013 04:35PM
January 18, 2013 04:12AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.