Skip to content

Instantly share code, notes, and snippets.

@henryhund
Created April 13, 2016 19:32
Show Gist options
  • Save henryhund/fa4e0cef32dc316b930b09d59e971fd8 to your computer and use it in GitHub Desktop.
Save henryhund/fa4e0cef32dc316b930b09d59e971fd8 to your computer and use it in GitHub Desktop.
/*
Include Parts 1 and 2
*/
ae_oppy_closed_won_activity_values AS
( SELECT ae_oppys_won_visits.oppy_id AS oppy_id, visit_type, visit_details, COUNT, amount,
round(amount/COUNT,2) AS mrr_per_visit
FROM ae_oppys_won_visits
INNER JOIN
( SELECT COUNT(*) AS COUNT,
oppy_id
FROM ae_oppys_won_visits
GROUP BY oppy_id ) counts ON counts.oppy_id = ae_oppys_won_visits.oppy_id ),
total_mrr_per_activity AS
( SELECT visit_type,
visit_details,
sum(mrr_per_visit) AS total_mrr
FROM ae_oppy_closed_won_activity_values
GROUP BY visit_type,
visit_details )
SELECT *
FROM total_mrr_per_activity
Raw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment