Skip to content

Instantly share code, notes, and snippets.

@si
Created February 20, 2012 11:40
Show Gist options
  • Save si/1868882 to your computer and use it in GitHub Desktop.
Save si/1868882 to your computer and use it in GitHub Desktop.
How to compare integers and dates on current and next records
I have a table of petrol purchases, each recording the current odometer reading:
id | odometer | user_id | created
-------------------------------
2 | 63446 | 1 | 2012-01-15 11:27:57
4 | 63835 | 1 | 2012-01-19 17:09:37
5 | 64145 | 1 | 2012-01-28 13:02:08
I want to return each row along with a distance and days lasted for each record (comparing the current record with the next record).
@rythie
Copy link

rythie commented Feb 20, 2012

Pretty much the point the entire dataset and indexes don't fit in memory anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment