Skip to content

Instantly share code, notes, and snippets.

@theosanderson
Created March 20, 2019 23:33
Show Gist options
  • Save theosanderson/180dc844359f7ee7a330bf190370cf2f to your computer and use it in GitHub Desktop.
Save theosanderson/180dc844359f7ee7a330bf190370cf2f to your computer and use it in GitHub Desktop.
Identify fastest growing petitions (min time between two defined numbers of signatures)
SELECT *, count_diff/time_diff AS rate FROM (SELECT petitions.action AS petitition, (countb2-count1) AS count_diff, t2-t1 AS time_diff FROM (SELECT * FROM (SELECT MIN(count) AS count1, petition_id AS pid1 FROM timeseries WHERE count>100000 GROUP BY petition_id) a INNER JOIN (SELECT time AS t1, petition_id AS pid2, count AS count2 FROM timeseries) b ON count1=count2 AND pid1=pid2) first INNER JOIN (SELECT * FROM (SELECT MIN(count) AS countb1, petition_id AS pidb1 FROM timeseries WHERE count>150000 GROUP BY petition_id) a INNER JOIN (SELECT time AS t2, petition_id AS pidb2, count AS countb2 FROM timeseries) b ON countb1=countb2 AND pidb1=pidb2) second ON pid1 = pidb1 AND count1 !=countb1 INNER JOIN petitions ON pid1=petitions.id ORDER BY time_diff) c ORDER BY rate DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment