Created
October 30, 2015 02:25
-
-
Save jaymay/4c02d759e00cfc445800 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
SELECT | |
agent_id, | |
agent_type, | |
is_owner, | |
agent_name, | |
agent_email, | |
subquery.* | |
FROM | |
(SELECT | |
account_id, | |
run_at, | |
subdomain, | |
SUM(satisfaction_prediction_enabled) satisfaction_prediction_enabled, | |
SUM(satisfaction_ratings_last_90_days) satisfaction_ratings_last_90_days, | |
SUM(views_using_satisfaction_probability) views_using_satisfaction_probability, | |
SUM(business_rules_using_satisfaction_probability) business_rules_using_satisfaction_probability | |
FROM | |
accounts a | |
INNER JOIN accounts_settings s USING (account_id , run_at) | |
INNER JOIN satisfaction_prediction p USING (account_id , run_at) | |
WHERE | |
a.run_at = (SELECT | |
MAX(run_at) | |
FROM | |
accounts) | |
AND a.is_owner_zendesk = 0 | |
AND a.plan_type = 4 | |
GROUP BY account_id | |
HAVING satisfaction_ratings_last_90_days > 1000) sub_query | |
INNER JOIN | |
agent_email_addresses d USING (account_id , run_at) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated to include "Admins" only, locale is English default and fixed the sub_query reference: