Find difference between sequential rows mysql, no row ID -
objective: difference between value in row , value in next row (i'm using mysql). have table "events":
step: timestamp: leave store 1400000000 buy hamburgers 1400000002 big party 1400000005
so result we'd expect is:
2 3
complication 1: table doesn't have id column, can't this:
select (e2.timestamp - e1.timestamp) events e1, events e2 (e1.id + 1) = e2.id
complication 2: i'm using database connection (splunk) won't allow me create or alter temporary tables (otherwise i'd add id column). hosed?
thank you!
use user variable hold timestamp previous line.
select step, timestamp - @prevtime diff, @prevtime := timestamp events cross join (select @prevtime := 0) x order timestamp
Comments
Post a Comment