Last active
May 20, 2021 17:08
-
-
Save tervay/5ff1a2f596f990d18f66c5f8506e7c20 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 | |
tname, | |
awardCount, | |
eventCount, | |
awardCount / eventCount AS awardsPerEvent | |
FROM ( | |
SELECT | |
ATM.name AS tname, | |
COUNT(A.name_str) AS awardCount | |
FROM ( `tbatv-prod-hrd.the_blue_alliance.award` AS A | |
JOIN | |
`tbatv-prod-hrd.the_blue_alliance.event` AS E | |
ON | |
A.event.name = E.__key__.name ), | |
UNNEST (A.team_list) AS ATM | |
WHERE | |
E.official = TRUE | |
GROUP BY | |
tname | |
ORDER BY | |
awardCount DESC) AS Q1 | |
INNER JOIN ( | |
SELECT | |
team.name AS teamName, | |
COUNT(E.__key__.name) AS eventCount | |
FROM | |
`tbatv-prod-hrd.the_blue_alliance.eventTeam` AS ET | |
JOIN | |
`tbatv-prod-hrd.the_blue_alliance.event` AS E | |
ON | |
E.__key__.name = ET.event.name | |
WHERE | |
((NOT E.event_type_enum IN (4, | |
6)) | |
OR (ET.year < 2001)) | |
AND (ET.year < 2021) | |
AND (official = TRUE) | |
GROUP BY | |
teamName | |
HAVING | |
COUNT(E.__key__.name) > 10) AS Q2 | |
ON | |
Q1.tname = Q2.teamname | |
ORDER BY | |
awardsPerEvent DESC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment