SQL Lab 4: Answer
How many lifetime hits does Barry Bonds have?
SELECT SUM(stats.hits)
FROM players INNER JOIN stats ON players.id = stats.player_id
WHERE players.first_name = 'Barry'
AND players.last_name = 'Bonds';
What are the first and last names of the players who played for the 2020 Chicago Cubs?
SELECT players.first_name, players.last_name
FROM stats
INNER JOIN teams ON teams.id = stats.team_id
INNER JOIN players ON players.id = stats.player_id
WHERE teams.year = 2020
AND teams.name = "Chicago Cubs";
Who hit the most home runs in 2019, and what team did they play for?
SELECT teams.name, players.first_name, players.last_name, stats.home_runs
FROM stats
INNER JOIN teams ON teams.id = stats.team_id
INNER JOIN players ON players.id = stats.player_id
WHERE teams.year = 2019
ORDER BY stats.home_runs DESC
LIMIT 1;
Who was the leading home run hitter for each team in 2019?
SELECT teams.name, players.first_name, players.last_name, MAX(stats.home_runs)
FROM stats
INNER JOIN teams ON teams.id = stats.team_id
INNER JOIN players ON players.id = stats.player_id
WHERE teams.year = 2019
GROUP BY teams.name;