I have used the Lahman baseball statistics database for this project. The database contains pitching, hitting, and fielding statistics for Major League Baseball from 1871 through 2017. It includes data from the two current leagues (American and National), four other "major" leagues (American Association, Union Association, Players League, and Federal League), and the National Association of 1871-1875.
The database is comprised of the following main tables:
People - Player names, date of birth (DOB), and biographical info
Batting - batting statistics
Pitching - pitching statistics
Fielding - fielding statistics
The main tables are supplemented by other, smaller tables.
-
Basics
- In the
people
table, find thenamefirst
,namelast
andbirthyear
for all players with weight greater than 300 pounds. - Find the
namefirst
,namelast
andbirthyear
of all players whosenamefirst
field contains a space. - From the
people
table, group together players with the samebirthyear
, and report thebirthyear
, averageheight
, and number of players for eachbirthyear
. Order the results bybirthyear
in ascending order. - Following the results of Part iii, now only include groups with an average height >
70
. Again order the results bybirthyear
in ascending order.
- In the
-
Hall of Fame Schools
- Find the
namefirst
,namelast
,playerid
andyearid
of all people who were successfully inducted into the Hall of Fame in descending order ofyearid
. - Find the people who were successfully inducted into the Hall of Fame and played in college at a school located in the state of California. For each person, return their
namefirst
,namelast
,playerid
,schoolid
, andyearid
in descending order ofyearid
. Break ties onyearid
byschoolid, playerid
(ascending). (For this question,yearid
refers to the year of induction into the Hall of Fame). - Find the
playerid
,namefirst
,namelast
andschoolid
of all people who were successfully inducted into the Hall of Fame -- whether or not they played in college. Return people in descending order ofplayerid
. Break ties onplayerid
byschoolid
(ascending). (Note:schoolid
will beNULL
if they did not play in college.)
- Find the
-
- Find the
playerid
,namefirst
,namelast
,yearid
and single-yearslg
(Slugging Percentage) of the players with the 10 best annual Slugging Percentage recorded over all time. For statistical significance, only include players with more than 50 at-bats in the season. Order the results byslg
descending, and break ties byyearid, playerid
(ascending). - Following the results from Part i, find the
playerid
,namefirst
,namelast
andlslg
(Lifetime Slugging Percentage) for the players with the top 10 Lifetime Slugging Percentage. Note that the database only gives batting information broken down by year; you will need to convert to total information across all time (from the earliest date recorded up to the last date recorded) to computelslg
. - Find the
namefirst
,namelast
and Lifetime Slugging Percentage (lslg
) of batters whose lifetime slugging percentage is higher than that of San Francisco favorite Willie Mays. You may include Willie Mays' playerid in your query (mayswi01
), but you may not include his slugging percentage -- you should calculate that as part of the query. (Test your query by replacingmayswi01
with the playerid of another player -- it should work for that player as well! We may do the same in the autograder.)
- Find the
-
Salaries
- Find the
yearid
, min, max, average and standard deviation of all player salaries for each year recorded, ordered byyearid
in ascending order. - For salaries in 2016, compute a histogram. Divide the salary range into 10 equal bins from min to max, with
binid
s 0 through 9, and count the salaries in each bin. Return thebinid
,low
andhigh
values for each bin, as well as the number of salaries in each bin, with results sorted from smallest bin to largest. - Now let's compute the Year-over-Year change in min, max and average player salary. For each year with recorded salaries after the first, return the
yearid
,mindiff
,maxdiff
, andavgdiff
with respect to the previous year. Order the output byyearid
in ascending order. (You should omit the very first year of recorded salaries from the result.) - In 2001, the max salary went up by over $6 million. Write a query to find the players that had the max salary in 2000 and 2001. Return the
playerid
,namefirst
,namelast
,salary
andyearid
for those two years. If multiple players tied for the max salary in a year, return all of them. - Each team has at least 1 All Star and may have multiple. For each team in the year 2016, give the
teamid
anddiffAvg
(the difference between the team's highest paid all-star's salary and the team's lowest paid all-star's salary). Order your final solution byteamid
. NOTE: Due to some discrepancies in the database, please draw your team names from the All-Star table (so use allstarfull.teamid in the SELECT statement for this).
- Find the