Skip to content

Instantly share code, notes, and snippets.

@preetamtt
Last active April 17, 2018 19:38
Show Gist options
  • Save preetamtt/6d4276e6b87fcfed0dcfd48917740661 to your computer and use it in GitHub Desktop.
Save preetamtt/6d4276e6b87fcfed0dcfd48917740661 to your computer and use it in GitHub Desktop.
#standardsql
WITH agg1 AS(
SELECT device_category, result_position, COUNT(*) as num_contacts
FROM sandbox.ir_ranking_contacts_td_apr17_18
WHERE quote_pk IS NOT NULL AND quote_pk > 0
GROUP BY 1,2
),
agg2 AS (
SELECT device_category, result_position, num_contacts*100/total_contacts as perc_total_contacts
FROM agg1 a, (SELECT COUNT(*) as total_contacts FROM sandbox.ir_ranking_contacts_td_apr17_18 WHERE quote_pk IS NOT NULL AND quote_pk > 0) b
)
SELECT * FROM agg2 ORDER BY 3 DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment