Created
January 27, 2014 14:44
-
-
Save omarqureshi/8649747 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
with stddeviation as ( | |
select stddev(extract (epoch from coalesce(deactivated_at, now()) - created_at)) as s from users where type = 'ServiceUser' | |
), | |
average as ( | |
select avg(extract (epoch from coalesce(deactivated_at, now()) - created_at)) as a from users where type = 'ServiceUser' | |
) | |
select avg(coalesce(deactivated_at, now()) - created_at) as average | |
from users, average, stddeviation | |
where type = 'ServiceUser' | |
and extract(epoch from coalesce(deactivated_at, now()) - created_at) < average.a + (stddeviation.s * 2) | |
and extract(epoch from coalesce(deactivated_at, now()) - created_at) > average.a - (stddeviation.s * 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment