SlideShare a Scribd company logo
Hockey
By 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) numplayers
FROM
(SELECT playerID, COUNT(DISTINCT year) numyears, birthcity
FROM Scoring JOIN Master USING (playerID)
WHERE GP>0
GROUP BY 1, 3
HAVING numyears>=15)
GROUP BY birthcity
HAVING numplayers>2
ORDER BY 2 DESC;
sub-query to find playerIDs
associated with at least 15
active 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 Master
WHERE birthcity IS NOT NULL
GROUP BY birthcity
ORDER BY 2 DESC
LIMIT 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_Player
FROM HOF JOIN Master USING(hofID)
WHERE birthCountry IS NOT NULL
GROUP 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
numRef
FROM 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.year
FROM Scoring s JOIN Master m USING (playerID);
SELECT coachID, m.firstName, m.lastName, COUNT(DISTINCT a.playerID)
AS NumPlayersCoached, COUNT(DISTINCT c.year) AS Experience
FROM 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.lastName
ORDER BY CntPlayersCoached DESC
LIMIT 20;
Show top 20 coaches that produced the highest number of
awarded players. Show also, their years of coaching
experience.
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 Age
FROM Master JOIN AwardsPlayers using (playerID)
GROUP BY lastName, firstName
ORDER BY NumAwards DESC
LIMIT 20;
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.lastName
FROM 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, coachID
ORDER 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.

More Related Content

PPTX
Presentacio power point google drive sofia oliveira
PPTX
Presentacio power point dropbox sofia oliveira
PPTX
Pr2 exercici 2.1 sofia oliveira 1
PDF
Anduiza y bosch
PPTX
Pr2 exercici 2 sofia oliveira 1
PDF
Dynamic_Positioning_Requirement_for_MODUs_and_Other_Vessels_Conducting_Outer_...
PDF
Serving Student Veterans at UC San Diego-1 Year Later Final [Read-Only]
PDF
หน่วยที่ 1
Presentacio power point google drive sofia oliveira
Presentacio power point dropbox sofia oliveira
Pr2 exercici 2.1 sofia oliveira 1
Anduiza y bosch
Pr2 exercici 2 sofia oliveira 1
Dynamic_Positioning_Requirement_for_MODUs_and_Other_Vessels_Conducting_Outer_...
Serving Student Veterans at UC San Diego-1 Year Later Final [Read-Only]
หน่วยที่ 1
Ad

Database 371 Final Presentation

  • 1. Hockey By Sara Borlak, Cindy Tu, and Justine Wendland
  • 3. 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) numplayers FROM (SELECT playerID, COUNT(DISTINCT year) numyears, birthcity FROM Scoring JOIN Master USING (playerID) WHERE GP>0 GROUP BY 1, 3 HAVING numyears>=15) GROUP BY birthcity HAVING numplayers>2 ORDER BY 2 DESC; sub-query to find playerIDs associated with at least 15 active years of game play
  • 4. Note that the top two cities are Montreal and Toronto, where Montreal has produced more than twice as many long-term players.
  • 5. Compare previous result to: Number of players born in each city SELECT birthcity, COUNT(playerID) FROM Master WHERE birthcity IS NOT NULL GROUP BY birthcity ORDER BY 2 DESC LIMIT 30;
  • 6. Toronto has produced over 100 more players than Montreal, but approximately half as many long-term players.
  • 8. 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_Player FROM HOF JOIN Master USING(hofID) WHERE birthCountry IS NOT NULL GROUP BY birthCountry;
  • 9. Number of Players in each Country who made it into the Hall of Fame
  • 10. 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 numRef FROM HOF JOIN Master USING(hofID) WHERE birthCountry=’Canada’ GROUP BY birthState;
  • 11. The Number of Players, Referees and Linesman in each Province in Canada who have been inducted into the Hockey Hall of Fame
  • 13. 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.year FROM Scoring s JOIN Master m USING (playerID);
  • 14. SELECT coachID, m.firstName, m.lastName, COUNT(DISTINCT a.playerID) AS NumPlayersCoached, COUNT(DISTINCT c.year) AS Experience FROM 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.lastName ORDER BY CntPlayersCoached DESC LIMIT 20; Show top 20 coaches that produced the highest number of awarded players. Show also, their years of coaching experience.
  • 16. 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 Age FROM Master JOIN AwardsPlayers using (playerID) GROUP BY lastName, firstName ORDER BY NumAwards DESC LIMIT 20;
  • 18. Show all the Coaches these Top20 Awarded players have worked with. SELECT a.playerID, p.firstName, p.lastName, coachID, m.firstName, m.lastName FROM 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, coachID ORDER BY p.firstName, p.lastName
  • 19. Who are the coaches of the most awarded player? The success of Wayne Gretzky was shaped by 33 different coaches!
  • 20. Most prestigious coach Scotty Bowman has taught 6 of the Top 20 players with the most awards in all times.