Skip to content

Instantly share code, notes, and snippets.

@allthesignals
Created November 3, 2017 16:46
Show Gist options
  • Select an option

  • Save allthesignals/65937f90015a9a06d04d3bd6ac1724de to your computer and use it in GitHub Desktop.

Select an option

Save allthesignals/65937f90015a9a06d04d3bd6ac1724de to your computer and use it in GitHub Desktop.
SELECT *, (t2.historic_comparison_sum - t1.sum) as delta_sum, (t2.historic_comparison_m - t1.m) as delta_m FROM ( SELECT regexp_replace(lower(variable), '[^A-Za-z0-9]', '_', 'g') as variable, regexp_replace(lower(profile), '[^A-Za-z0-9]', '_', 'g') as profile, regexp_replace(lower(category), '[^A-Za-z0-9]', '_', 'g') as category, sum, base, m FROM ( SELECT SUM(e), SQRT( SUM( POWER(m, 2) ) ) AS m, variable FROM support_fact_finder WHERE geoid IN ('4056100','4053900','4053100','4066701','4061301','3027900') AND year = 'Y2011-2015' GROUP BY variable) support_fact_finder INNER JOIN support_fact_finder_meta_update ON support_fact_finder_meta_update.variablename = support_fact_finder.variable) t1 INNER JOIN ( SELECT sum AS historic_comparison_sum, m AS historic_comparison_m, variable as t2_var FROM ( SELECT regexp_replace(lower(variable), '[^A-Za-z0-9]', '_', 'g') as variable, regexp_replace(lower(profile), '[^A-Za-z0-9]', '_', 'g') as profile, regexp_replace(lower(category), '[^A-Za-z0-9]', '_', 'g') as category, sum, base, m FROM ( SELECT SUM(e), SQRT( SUM( POWER(m, 2) ) ) AS m, variable FROM support_fact_finder WHERE geoid IN ('4056100','4053900','4053100','4066701','4061301','3027900') AND year = 'Y2006-2010' GROUP BY variable) support_fact_finder INNER JOIN support_fact_finder_meta_update ON support_fact_finder_meta_update.variablename = support_fact_finder.variable) t ) t2 ON t2.t2_var = t1.variable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment