My original data is as follows:
sid id amount
1 12 30
2 45 30
3 45 50
4 78 80
5 78 70
The desired output is follows:
sid id amount
1 12 30
2 45 30
3 45 30
4 78 80
5 78 80
THe intention is to take the amount where id appears first and update the amount the second time it appears I am trying the following code:
UPDATE foo AS f1
JOIN
( SELECT cur.sl, cur.id,
cur.amount AS balance
FROM foo AS cur
JOIN foo AS prev
ON prev.id = cur.id
GROUP BY cur.tstamp
) AS p
ON p.id = a.id
SET a.amount = p.amount ;