Skip to content

Instantly share code, notes, and snippets.

@jaymay
Created February 4, 2016 14:11
Show Gist options
  • Save jaymay/247d41ef9d3ba48ef59b to your computer and use it in GitHub Desktop.
Save jaymay/247d41ef9d3ba48ef59b to your computer and use it in GitHub Desktop.
ML eligibility
select a.plan_type,
count(*) total_accounts,
sum(if(p.satisfaction_ratings_last_90_days > 1000, mrr.mrr_amt, 0)) / sum(mrr_amt) perc_eligible_satisfaction_prediction,
sum(if(r.num_shared_macros > 10, mrr.mrr_amt, 0)) / sum(mrr_amt) perc_eligible_macro_suggestion,
sum(if(co.num_hc_articles > 10, mrr.mrr_amt, 0)) / sum(mrr_amt) perc_eligible_content_suggestion
from accounts_settings s
inner join accounts a using (account_id, run_at)
inner join fdw_mrr mrr using (account_id, run_at)
left join count_objects co using (account_id, run_at)
left join ticket_rules r using (account_id, run_at)
left join satisfaction_prediction p using (account_id, run_at)
where s.run_at = (select max(run_at) from accounts)
and a.account_type = 'customer'
group by a.plan_type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment