Skip to content

Instantly share code, notes, and snippets.

@dnasca
Created April 21, 2015 04:50
Show Gist options
  • Select an option

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

Select an option

Save dnasca/a44d2b5c3477a14d29e0 to your computer and use it in GitHub Desktop.
Batting Average on Balls In Play (BABIP) - measures how often a ball in play goes for a hit. A ball is “in play” when the plate appearance ends in something other than a strikeout, walk, hit batter, catcher’s interference, sacrifice bunt, or home run. In other words, the batter put the ball in play and it didn’t clear the outfield fence.
#using the Lahman Baseball Database
SELECT
m.birthYear AS BIRTH,
CONCAT(m.nameFirst, ' ', m.nameLast) AS NAME,
SUM(b.AB) AS AB,
SUM((b.H - b.HR)/(b.AB - b.SO - b.HR + COALESCE(b.SF, 0))) AS BABIP #Batting Average on Balls In Play
FROM
Batting b,
Master m
WHERE
b.playerID = m.playerID AND yearID = 2014
GROUP BY b.playerID
HAVING AB > 300
AND BIRTH > 1900
ORDER BY BABIP ASC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment