Created
April 13, 2016 19:32
-
-
Save henryhund/fa4e0cef32dc316b930b09d59e971fd8 to your computer and use it in GitHub Desktop.
Part 3 of Lead Engagement Scoring Query: https://gist.github.com/henryhund/dc9b2d47c00f018c098c#file-lead_scoring_complete_query-sql
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
/* | |
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