row operation in same table and same coloumns

Posted by Raj on Stack Overflow See other posts from Stack Overflow or by Raj
Published on 2010-05-07T12:14:15Z Indexed on 2010/05/07 12:18 UTC
Read the original article Hit count: 281

Filed under:

Hi! i have a little problem to discuss i hope it will easy for you. suppose i have table A with 2 columns as

item          price
milk           25
milk           50
milk           100
Butter         25
Butter         100
Butter         200

now i want to display a table B derived from table A as

item          price growth rate
milk           0
milk           100
milk           100
Butter        100
Butter         200
Butter         100

formula for growth rate for row1 is

((row[1]-row[0])/row[0])*100
eg for 1st row ((50-25)/25)*100

can you suggest a SQl Query for it

© Stack Overflow or respective owner

Related posts about row