Created
January 27, 2015 20:25
-
-
Save jaymay/131ff44790d82a400cd3 to your computer and use it in GitHub Desktop.
active starter customers query
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
set @run_at = '2014-12-31 00:00:00'; | |
select a.account_id, a.subdomain, aa2.num_active_agents_90_days | |
from accounts a | |
inner join | |
(select aa.account_id, count(*) num_active_agents_90_days, @run_at as run_at, 'all' as timespan | |
from active_agents aa | |
where aa.run_at between subdate(@run_at, interval 90 day) and @run_at | |
and timespan = '1d' | |
group by aa.account_id | |
) aa2 | |
using (account_id, run_at, timespan) | |
where a.run_at = @run_at and a.timespan = 'all' and a.plan_type = 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment