Database 371 Final Presentation
-
Upload
justine-wendland -
Category
Documents
-
view
154 -
download
1
Transcript of Database 371 Final Presentation
HockeyBy Sara Borlak, Cindy Tu, and Justine
Wendland
Background
Player
What are the birth cities of players who have played in the league for at least 15 years? Of these birth cities, how many such players has each produced? Only show birth cities having produced more than two such players.
SELECT birthcity, COUNT(playerID) numplayersFROM
(SELECT playerID, COUNT(DISTINCT year) numyears, birthcityFROM Scoring JOIN Master USING (playerID)WHERE GP>0GROUP BY 1, 3HAVING numyears>=15)
GROUP BY birthcityHAVING numplayers>2ORDER BY 2 DESC;
sub-query to find playerIDs associated with at least 15active years of game play
Note that the top two cities are Montreal and Toronto, where Montreal has produced more than twice as many long-term players.
Compare previous result to: Number of players born in each city
SELECT birthcity, COUNT(playerID)FROM MasterWHERE birthcity IS NOT NULLGROUP BY birthcityORDER BY 2 DESCLIMIT 30;
Toronto has produced over 100 more players than Montreal, but approximately half as many long-term players.
Hall of Famers
Show the breakdown of country of origin for the Players that have made it to the Hall of Fame
SELECT birthCountry, COUNT(hofID) AS Hall_of_Fame_PlayerFROM HOF JOIN Master USING(hofID)WHERE birthCountry IS NOT NULLGROUP BY birthCountry;
Number of Players in each Country who made it into the Hall of Fame
Find the number of Canadian Hall of Famers per province, then group them by categories
SELECT birthState,SUM(CASE WHEN category=’Player’ THEN 1 ELSE 0 END) AS numPlayer,SUM(CASE WHEN category=Builder’ THEN 1 ELSE 0 END) AS numBuilder,SUM(CASE WHEN category=’Referee/Linesman’ THEN 1 ELSE 0 END) AS numRefFROM HOF JOIN Master USING(hofID)WHERE birthCountry=’Canada’GROUP BY birthState;
The Number of Players, Referees and Linesman in each Province in Canada who have been inducted into the Hockey Hall of Fame
Relationship between
Players, Awards, and Coaches
Show top 20 coaches that produced the highest number of awarded players. Show also, their years of coaching experience.
CREATE VIEW PlayerTeamYear AS
SELECT m.playerID, m.firstName, m.lastName, s.tmID, s.lgID, s.yearFROM Scoring s JOIN Master m USING (playerID);
SELECT coachID, m.firstName, m.lastName, COUNT(DISTINCT a.playerID) AS NumPlayersCoached, COUNT(DISTINCT c.year) AS ExperienceFROM AwardsPlayers a JOIN PlayerTeamYear p USING(playerID) JOIN Coaches c USING(tmID, lgID, year) JOIN Master m USING (coachID)GROUP BY coachID, m.firstName, m.lastNameORDER BY CntPlayersCoached DESCLIMIT 20;
Show top 20 coaches that produced the highest number of awarded players. Show also, their years of coaching experience.
Show the Top20 player who has been awarded with the most awards with their ages.
CREATE VIEW Top20Players AS
SELECT lastName, firstName, COUNT(award) AS NumAwards, CASE WHEN deathYear IS NOT NULL THEN (deathyear - birthYear) ELSE (strftime('%Y', 'now') - birthYear) END AS AgeFROM Master JOIN AwardsPlayers using (playerID)GROUP BY lastName, firstNameORDER BY NumAwards DESCLIMIT 20;
Show all the Coaches these Top20 Awarded players have worked with.
SELECT a.playerID, p.firstName, p.lastName, coachID, m.firstName, m.lastNameFROM AwardsPlayers a JOIN PlayerTeamYear p USING (playerID) JOIN Coaches c USING (tmID, lgID, year) JOIN Master m USING (coachID)WHERE p.lastName IN (SELECT lastName FROM Top20players) AND p.firstName IN (SELECT firstName FROM Top20players)GROUP BY a.playerID, coachIDORDER BY p.firstName, p.lastName
Who are the coaches of the most awarded player?
The success of Wayne Gretzky was shaped by 33 different coaches!
Most prestigious coach
Scotty Bowman has taught 6 of the Top 20 players with the most awards in all times.