Skip to content

Instantly share code, notes, and snippets.

@dnasca
Last active August 29, 2015 14:19
Show Gist options
  • Select an option

  • Save dnasca/fafb44aab316e5507ee5 to your computer and use it in GitHub Desktop.

Select an option

Save dnasca/fafb44aab316e5507ee5 to your computer and use it in GitHub Desktop.
This query will return all players from 1871 - 2014 who had at least 7000 AB's during their career. The list is sorted by the lowest->strikeout percentages (SOPERC)
#using the Lahman Baseball Database
SELECT
CONCAT(YEAR(m.debut), ' - ', YEAR(m.finalGame)) AS YEARSPLAYED,
CONCAT(m.nameFirst, ' ', m.nameLast) AS NAME,
SUM(b.AB) AS AB,
ROUND(SUM(b.so) / SUM(b.AB + b.BB + b.HBP + COALESCE(b.SF, 0)) * 100, 2) AS SOPERC
FROM
Batting b,
Master m
WHERE
b.playerID = m.playerID
GROUP BY b.playerID HAVING AB > 7000
AND YEARSPLAYED <> 'null'
ORDER BY SOPERC ASC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment