I have the input like:
+-----+---------+-------+------------+------------+
| key | company | price | week_start | price_diff |
+-----+---------+-------+------------+------------+
| 123 | xxx | 15 | 02-06-2015 | |
| 456 | xxx | 20 | 02-06-2015 | |
| 789 | yyy | 30 | 02-06-2015 | |
| 122 | zzz | 40 | 02-06-2015 | |
| 123 | xxx | 50 | 09-06-2015 | |
| 456 | xxx | 60 | 09-06-2015 | |
| 333 | yyy | 70 | 09-06-2015 | |
+-----+---------+-------+------------+------------+
expected output:
update the column price_diff
+-----+---------+-------+------------+------------+
| key | company | price | week_start | price_diff |
+-----+---------+-------+------------+------------+
| 123 | xxx | 15 | 02-06-2015 | |
| 456 | xxx | 20 | 02-06-2015 | |
| 789 | yyy | 30 | 02-06-2015 | |
| 122 | zzz | 40 | 02-06-2015 | |
| 123 | xxx | 50 | 09-06-2015 | 35 |
| 456 | xxx | 60 | 09-06-2015 | 40 |
| 333 | yyy | 70 | 09-06-2015 | |
+-----+---------+-------+------------+------------+
for company= 'xxx'
and key = 123
I want to take the price difference based on week_start
. From the above input for company = 'xxx'
and key = 123
, second week has price = 50
and the first week price = 15. I need to update the price_diff with difference of those two values.
Thanks In Advance