Created
August 14, 2013 17:39
-
-
Save jmelloy/6233479 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select dp.id deck_page_id, dqry.id deck_query_id, dqry.name, dqry.sla, dqry.numerator_value, dqry.numerator_function, dqry.denominator_value, | |
dqry.denominator_function, dqry.deck_group_id, dqry.deck_group_order, dqry.graph_type, dqry.graph_legend, num.year, num.week_number, num.value num_value, denom.value denom_value, num.value / denom.value div_value, 100 - num.value / denom.value * 100.0 inv_percentage | |
from deck_page dp | |
join deck_page_group dpg on (dp.id = dpg.deck_page_id) | |
join deck_query dqry on (dpg.id= dqry.deck_group_id) | |
join ( | |
SELECT * | |
FROM | |
(SELECT * FROM deck_query_weekly_rollup) p | |
UNPIVOT (value FOR agg_type IN (sum_value, avg_value, min_value, max_value, tp_25, tp_50, tp_75, tp_90) | |
) AS vals | |
) num on (numerator_value = num.query_value_id and numerator_function = num.agg_type) | |
left join ( | |
SELECT * | |
FROM | |
(SELECT * FROM deck_query_weekly_rollup) p | |
UNPIVOT (value FOR agg_type IN (sum_value, avg_value, min_value, max_value, tp_25, tp_50, tp_75, tp_90) | |
) AS vals | |
) denom on (denominator_value = denom.query_value_id and denominator_function = denom.agg_type and num.week_number = denom.week_number) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment