Last active
August 10, 2018 21:21
-
-
Save maxp-edcast/9a46e2817ddb4e77dc1a8c0759a51f2d to your computer and use it in GitHub Desktop.
query
This file contains 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 | |
SUM(smartbites_created_count) AS smartbites_created, | |
SUM(smartbites_consumed_count) AS smartbites_consumed, | |
AVG(user_metrics_aggregations.time_spent_minutes) AS average_session, | |
COUNT(DISTINCT(teams_users.user_id)) AS total_users, | |
teams.id AS team_id, | |
COUNT(DISTINCT(teams_users.user_id)) AS active_users, | |
COUNT(DISTINCT(teams_users.user_id)) AS new_users | |
FROM user_metrics_aggregations | |
INNER JOIN users ON users.id = user_metrics_aggregations.user_id | |
INNER JOIN teams_users ON teams_users.user_id = users.id | |
INNER JOIN teams ON teams.id = teams_users.team_id | |
WHERE users.organization_id = 15 | |
AND user_metrics_aggregations.time_spent_minutes > 0 | |
GROUP BY team_id | |
) | |
UNION ALL | |
( | |
SELECT | |
SUM(smartbites_created_count) AS smartbites_created, | |
SUM(smartbites_consumed_count) AS smartbites_consumed, | |
AVG(user_metrics_aggregations.time_spent_minutes) AS average_session, | |
COUNT(DISTINCT(teams_users.user_id)) AS total_users, | |
teams.id AS team_id, | |
'' AS active_users, | |
COUNT(DISTINCT(teams_users.user_id)) AS new_users | |
FROM user_metrics_aggregations | |
INNER JOIN users ON users.id = user_metrics_aggregations.user_id | |
INNER JOIN teams_users ON teams_users.user_id = users.id | |
INNER JOIN teams ON teams.id = teams_users.team_id | |
WHERE users.organization_id = 15 | |
AND users.created_at > '2018/09/01' | |
AND users.created_at < '2018/09/01' | |
GROUP BY team_id | |
) | |
UNION ALL | |
( | |
SELECT | |
SUM(smartbites_created_count) AS smartbites_created, | |
SUM(smartbites_consumed_count) AS smartbites_consumed, | |
AVG(user_metrics_aggregations.time_spent_minutes) AS average_session, | |
COUNT(DISTINCT(teams_users.user_id)) AS total_users, | |
teams.id AS team_id, | |
'' AS active_users, | |
'' AS new_users | |
FROM user_metrics_aggregations | |
INNER JOIN users ON users.id = user_metrics_aggregations.user_id | |
INNER JOIN teams_users ON teams_users.user_id = users.id | |
INNER JOIN teams ON teams.id = teams_users.team_id | |
WHERE users.organization_id = 15 | |
GROUP BY team_id | |
) | |
ORDER BY new_users DESC | |
LIMIT 20 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment