Skip to content

Instantly share code, notes, and snippets.

@jatorre
Last active December 27, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jatorre/7336704 to your computer and use it in GitHub Desktop.
Save jatorre/7336704 to your computer and use it in GitHub Desktop.
WITH summary_groups as(
WITH summary as (
select (row_number() over (order by time asc nulls last)+1)/2 as rownum,time
from sensor_log_2013_10_27_12_01
order by time asc)
SELECT
max(time) OVER(PARTITION BY rownum) -
min(time) OVER(PARTITION BY rownum) diff
FROM summary)
SELECT
avg(diff) as diffavg,
(SELECT max(time)-min(time) as total_diff FROM sensor_log_2013_10_27_12_01 as subq)/avg(diff) as num_steps
FROM summary_groups
WHERE diff>0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment