Skip to content

Instantly share code, notes, and snippets.

@dnasca
Created April 21, 2015 03:44
Show Gist options
  • Select an option

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

Select an option

Save dnasca/1a8b2f9743c5313af818 to your computer and use it in GitHub Desktop.
Career singles
#using the Lahman Baseball Database
SELECT
m.birthYear AS BIRTH,
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,
SUM(b.h) AS H,
SUM(b.h - (2b + 3b + hr)) AS 1B
FROM
Batting b,
Master m
WHERE
b.playerID = m.playerID
GROUP BY b.playerID HAVING AB > 7000
AND YEARSPLAYED <> 'null'
AND BIRTH > 1900
ORDER BY 1B DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment