Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

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

Select an option

Save dnasca/2dbe1370acca643e6605 to your computer and use it in GitHub Desktop.
This query asks - Who are all the players between 1900 and 2014 with over 5000 at bats, include AB, BBPERC, SOPERC, and AVG, sort by SOPERC lowest->highest (Strike-out percentage)
##Using the baseball statistics dB found at http://www.seanlahman.com/baseball-archive/statistics/
SELECT
b.playerID,
CONCAT(m.nameFirst, ' ', m.nameLast) AS NAME,
SUM(b.AB) AS AB,
ROUND(b.bb / (b.AB + b.BB + b.HBP + COALESCE(b.SF, 0)) * 100, 2) AS BBPERC,
ROUND(b.so / (b.AB + b.BB + b.HBP + COALESCE(b.SF, 0)) * 100, 2) AS SOPERC,
ROUND(SUM(b.H) / SUM(b.AB), 3) AS AVG
FROM
Batting b,
Master m
WHERE
b.playerID = m.playerID
AND yearID BETWEEN 1900 AND 2014
GROUP BY b.playerID
HAVING SOPERC > 0 AND BBPERC > 0 AND AB > 5000
ORDER BY SOPERC ASC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment