| Author |
Topic |
|
Mondeo
Constraint Violating Yak Guru
287 Posts |
Posted - 2010-01-21 : 10:27:47
|
| Hi,I have a table similar to thisref,years,miles,special,price1,2,10000,0,1001,2,10000,1,1001,2,20000,0,01,2,20000,1,01,2,30000,0,2001,2,30000,1,200I want to loop through the table and for each ref calculate the 20,000 figures based on the 10,000 and 30,000 price of the same parameters (years,miles,special)The calculation is the ((30000 price - 10000 price) / 20 * 10) + 10000 priceSo in this example ((200 - 100) / 20 * 10) + 100 = 150Really stuck how to go about it.Thanks |
|
|
Kristen
Test
22859 Posts |
Posted - 2010-01-21 : 10:47:17
|
This perhaps?SELECT ref,years,miles,special,price, ((T30000.price - T10000.price) / 20 * 10) + T10000.price AS CalcPriceFROM MyTable AS T10000 JOIN MyTable AS T30000 ON T30000.years = T10000.years AND T30000.special = T10000.special AND T30000.miles = 30000WHERE T10000.miles = 10000 |
 |
|
|
|
|
|