Created
August 10, 2018 19:00
-
-
Save maxp-edcast/073fe5fff6fcfae1fa34c2ea2d1c3648 to your computer and use it in GitHub Desktop.
queries
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 | |
'' AS smartbites_created, | |
'' AS smartbites_consumed, | |
'' AS average_session, | |
'' AS total_users, | |
teams.id AS team_id, | |
COUNT(DISTINCT(teams_users.user_id)) AS active_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 | |
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 | |
LIMIT 20 |
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 | |
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 | |
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 | |
LIMIT 20 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment