Skip to content

Instantly share code, notes, and snippets.

@rochoa
Forked from javisantana/speed.sql
Last active August 29, 2015 14:27
Show Gist options
  • Save rochoa/444075983bd4fd100a68 to your computer and use it in GitHub Desktop.
Save rochoa/444075983bd4fd100a68 to your computer and use it in GitHub Desktop.
speed from a track table
WITH deltas as (
SELECT
st_distance(the_geom::geography, lag(the_geom::geography, 1) over(order by timestamp)) as ddist,
timestamp - lag(timestamp, 1) over(order by timestamp) as dt
from out_2 offset 1000
)
select avg(ddist/dt) as speed from deltas
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment