Database 371 Final Presentation

20
Hockey By Sara Borlak, Cindy Tu, and Justine Wendland

Transcript of Database 371 Final Presentation

Page 1: Database 371 Final Presentation

HockeyBy Sara Borlak, Cindy Tu, and Justine

Wendland

Page 2: Database 371 Final Presentation

Background

Player

Page 3: Database 371 Final Presentation

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

Page 4: Database 371 Final Presentation

Note that the top two cities are Montreal and Toronto, where Montreal has produced more than twice as many long-term players.

Page 5: Database 371 Final Presentation

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;

Page 6: Database 371 Final Presentation

Toronto has produced over 100 more players than Montreal, but approximately half as many long-term players.

Page 7: Database 371 Final Presentation

Hall of Famers

Page 8: Database 371 Final Presentation

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;

Page 9: Database 371 Final Presentation

Number of Players in each Country who made it into the Hall of Fame

Page 10: Database 371 Final Presentation

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;

Page 11: Database 371 Final Presentation

The Number of Players, Referees and Linesman in each Province in Canada who have been inducted into the Hockey Hall of Fame

Page 12: Database 371 Final Presentation

Relationship between

Players, Awards, and Coaches

Page 13: Database 371 Final Presentation

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);

Page 14: Database 371 Final Presentation

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.

Page 15: Database 371 Final Presentation
Page 16: Database 371 Final Presentation

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;

Page 17: Database 371 Final Presentation
Page 18: Database 371 Final Presentation

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

Page 19: Database 371 Final Presentation

Who are the coaches of the most awarded player?

The success of Wayne Gretzky was shaped by 33 different coaches!

Page 20: Database 371 Final Presentation

Most prestigious coach

Scotty Bowman has taught 6 of the Top 20 players with the most awards in all times.