I'm writing an application which tracks views of various items across time, and I've hit a bit of a snag. I need to get the difference in views between two adjacent updates. The updates are identified by a UNIQUE
key, containing the columns time
and id
. How would I be able to do this, without running multiple queries?
SELECT updates.views, (updates.views - <previous views>)
FROM updates JOIN stuff ON stuff.id = stuff.id
WHERE updates.time = '01-01-1970 00:00:00' AND stuff.owner = 'someone'