Skip to content

Instantly share code, notes, and snippets.

@henryhund
Created April 13, 2016 19:34
Show Gist options
  • Save henryhund/c9a218dbd56aa0fcea516c61c19210e5 to your computer and use it in GitHub Desktop.
Save henryhund/c9a218dbd56aa0fcea516c61c19210e5 to your computer and use it in GitHub Desktop.
/*
This is the final part of this query, which gives us leads ordered by aggregate score!
Include Parts 1, 2, 3 and 4
*/
SELECT sum(mrr_per_visit) as lead_score,
prospect_id
FROM all_prospects_visits
JOIN mrr_per_activity
ON all_prospects_visits.visit_type = mrr_per_activity.visit_type
AND all_prospects_visits.visit_details = mrr_per_activity.visit_details
GROUP BY prospect_id
ORDER BY lead_score DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment