Jump to content

Archived

This topic is now archived and is closed to further replies.

seran128

Finding the diference between two values

Recommended Posts

I have a table that looks like this

tbl_product

ID        Cost
1          5.23
2          3.76
7          25.22


now I want to run a query that returns the value of the difference between two product id's

like

psudeo code
finalcost = (select cost from tbl_products where id = '1') - (select cost from tbl_products where id = '2')

in this case finalcost should be 1.47

Is there a way to do this in one SQL statment

Share this post


Link to post
Share on other sites
SELECT a.price - b.price as diff
FROM prices a JOIN prices b
ON a.price_id = 1 AND b.price_id = 2

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.