Reputation: 600
I have a table 'price' looks like:
itemId, name, price, cover
1, Book, 30, paper
2, Phone, 100, box
3, Flower, 10, paper
And have a second table 'covers' looks like:
coverId, cover, price
1, paper, 5
2, box, 10
How can I get a return of items only with paper cover whis additional coloin of SUM (price of item + price of cover) ORDERred by SUM (price of item + price of cover), like this:
itemId, name, priceOfItemPluspriceOfCover
3, flower, 15
1, book, 35
Thank guys!
Upvotes: 0
Views: 34
Reputation: 1531
select price.itemid, price.name, sum(price.price, covers.price) as priceOfItemPluspriceOfCover
from price
inner join covers
on price.cover = covers.cover
Upvotes: 2
Reputation: 93754
Simple inner join
will work
select p.itemId, p.name, p.price+c.price
from price p
inner join covers c on p.cover = c.cover
Where c.cover = 'paper'
I would suggest you to store the coverid
in price table instead of the cover name and define a foreign key to maintain the data integrity
Upvotes: 2