Skip to content

Instantly share code, notes, and snippets.

@lcguida
Created December 12, 2016 11:30
Show Gist options
  • Save lcguida/75d13b1e4058afab25e4195072b019b5 to your computer and use it in GitHub Desktop.
Save lcguida/75d13b1e4058afab25e4195072b019b5 to your computer and use it in GitHub Desktop.
Running SQL Examaple
-- Dudu query:
select part_id,produced_at
from (select part_id,produced_at
,dense_rank () over (partition by part_id order by produced_at) as dr
from part_subhourly_data
where produced_at < now() - interval '100 days'
) p
where dr <= 5 and part_id = 1422
;
-- RESULTS:
1422;"2015-12-02 09:30:00"
1422;"2015-12-02 09:35:00"
1422;"2015-12-02 09:40:00"
1422;"2015-12-02 09:45:00"
1422;"2015-12-02 09:50:00"
--What is in the database?
SELECT part_id, produced_at FROM part_subhourly_data WHERE part_id = 1422 ORDER BY produced_at;
1422;"2015-12-02 09:30:00"
1422;"2015-12-02 09:35:00"
1422;"2015-12-02 09:40:00"
1422;"2015-12-02 09:45:00"
1422;"2015-12-02 09:50:00"
1422;"2015-12-02 09:55:00"
1422;"2015-12-02 10:00:00"
1422;"2015-12-02 10:05:00"
1422;"2015-12-02 10:10:00"
1422;"2015-12-02 10:15:00"
1422;"2015-12-02 10:20:00"
1422;"2015-12-02 10:25:00"
1422;"2015-12-02 10:30:00"
1422;"2015-12-02 10:35:00"
1422;"2015-12-02 10:40:00"
1422;"2015-12-02 10:45:00"
1422;"2015-12-02 10:50:00"
1422;"2015-12-02 10:55:00"
1422;"2015-12-02 11:00:00"
1422;"2015-12-02 11:05:00"
1422;"2015-12-02 11:10:00"
1422;"2015-12-02 11:15:00"
1422;"2015-12-02 11:20:00"
1422;"2015-12-02 11:25:00"
1422;"2015-12-02 11:30:00"
1422;"2015-12-02 11:35:00"
1422;"2015-12-02 11:40:00"
1422;"2015-12-02 11:45:00"
1422;"2015-12-02 11:50:00"
1422;"2015-12-02 11:55:00"
1422;"2015-12-02 12:00:00"
1422;"2015-12-02 12:05:00"
1422;"2015-12-02 12:10:00"
1422;"2015-12-02 12:15:00"
1422;"2015-12-02 12:20:00"
1422;"2015-12-02 12:25:00"
1422;"2015-12-02 12:30:00"
1422;"2015-12-02 12:35:00"
1422;"2015-12-02 12:40:00"
1422;"2015-12-02 12:45:00"
1422;"2015-12-02 12:50:00"
1422;"2015-12-02 12:55:00"
1422;"2015-12-02 13:00:00"
1422;"2015-12-02 13:05:00"
1422;"2015-12-02 13:10:00"
1422;"2015-12-02 13:15:00"
1422;"2015-12-02 13:20:00"
1422;"2015-12-02 13:25:00"
1422;"2015-12-02 13:30:00"
1422;"2015-12-02 13:35:00"
1422;"2015-12-02 13:40:00"
1422;"2015-12-02 13:45:00"
1422;"2015-12-02 13:50:00"
(...)
360929;1422;"2015-12-02 10:20:00";"";""pac"=>"3685""
360928;1422;"2015-12-02 10:25:00";"";""pac"=>"3494""
360927;1422;"2015-12-02 10:30:00";"";""pac"=>"3668""
360926;1422;"2015-12-02 10:35:00";"";""pac"=>"3730""
360925;1422;"2015-12-02 10:40:00";"";""pac"=>"3805""
(...) more data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment