Let’s say i have a table with the following data:
day1 item1 30
day1 item2 25
day1 item3 27
day2 item1 30
day2 item2 30
day2 item3 20
…
dayN item1 20
How would I structure a query that can give me the rate of change for each item on a daily basis.
day1 item1 rateOfChange:0
day1 item2 rateOfChange:-1
day1 item3 rateOfChange:5
day2 item1 rateOfChange:0
day2 item2 rateOfChange:2
My inital thought (without knowing sql too well), would be to loop through each day, and have a subquery that checks for the day before for each item and does a difference?
Thanks
If you table was called datatable with a day,item and value integer columns, this might do it