Now, what if I wanted the total price of Product ID 1? Of course, that's 2 * (10 + ((2 * 2) + (4 * 1))) = 36. But how could I achieve that in SQL? I've written several queries, but I always get weird errors. The below is what bane7378 and mastermate came up with last time:
select products.prodid,
isnull(sum(options.price*options.qty),0)+products.prodprice
from products left outer join options
on products.prodid= options.prodid
group by products.prodid,products.prodprice
At the time, I wasn't using a Quantity field for each Product. (Only the Product Option's had Quantity fields.)
Question
wessleym
This is a continuation of a question I asked last year: https://www.neowin.net/forum/topic/947194-sql-get-total-prices-of-child-records/
Let's say I have a few tables constructed like this:
Now, what if I wanted the total price of Product ID 1? Of course, that's 2 * (10 + ((2 * 2) + (4 * 1))) = 36. But how could I achieve that in SQL? I've written several queries, but I always get weird errors. The below is what bane7378 and mastermate came up with last time:
At the time, I wasn't using a Quantity field for each Product. (Only the Product Option's had Quantity fields.)
So how can I modify this query? Thank you!
Link to comment
Share on other sites
5 answers to this question
Recommended Posts