Created
December 8, 2014 05:44
-
-
Save RikkiGibson/6d7dde5960d378a751b6 to your computer and use it in GitHub Desktop.
Given a bunch of data on how many pins the players on each team knocked down each frame of each game, determine the wins and losses for all the teams in the league.
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 t.TeamName, ifnull(Wins, 0) Wins, ifnull(Total-Wins,0) Losses | |
from Team t | |
left join ( | |
select b.TeamID, count(*) Wins | |
from ( | |
select a.GameID, a.TeamID, max(Points) | |
from ( | |
select gf.GameID, gf.TeamID, sum(gf.FirstRoll + gf.SecondRoll) Points | |
from GameFrame gf | |
group by gf.GameID, gf.TeamID | |
order by GameID, Points desc | |
) a | |
group by a.GameID | |
) b | |
group by b.TeamID | |
) c on c.TeamID = t.TeamID | |
left join ( | |
select TeamID, count(*) Total | |
from ( | |
select distinct GameID, TeamID | |
from GameFrame | |
) d | |
group by TeamID | |
) e on e.TeamID = t.TeamID |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment