What you need is LAG
function. it exists in multiple databases including db2
Syntax would be something like this
SELECT CASE WHEN LAG(MyField, 1) OVER ( PARTITION BY MyID ORDER BY SomeThing ) IS NULL THEN 0
ELSE MyField - LAG(MyField, 1) OVER ( PARTITION BY MyID ORDER BY SomeThing )
END AS Result
FROM MyTable