The table contains the columns id
, timestamp
(eg. 2013-09-23 12:10:53), activity
and I want to add another column duration
which would contain the duration of each activity (ie. the difference between the next row time stamp and the current one).
I've tried this query:
UPDATE `MyTable` this SET `duration`=
(SELECT DATEDIFF(next.`timestamp`, curr.`timestamp`)
FROM `MyTable` curr
JOIN `MyTable` next
ON next.`id` = curr.`id`+1
WHERE this.`id` = curr.`id`)
And got this error:
#1093 - You can't specify target table 'this' for update in FROM clause
How can I go about doing that?