Last active
August 29, 2015 14:19
-
-
Save dnasca/ae45c967e5f847b18ac9 to your computer and use it in GitHub Desktop.
This query asks the question with the following constraints: Who are all the players in 2014 that had more than 10 HRs, 50 runs scored, 50 runs batted in, 10 stolen bases, and had at least 300 AB's? Also, for every player in the initial result set who met the requirements of HR>10, R>50, RBI>50, AB>300-- calculate the BBPERC (walks percentage) a…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ##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, | |
| SUM(b.HR) AS HR, | |
| SUM(b.R) AS R, | |
| SUM(b.RBI) AS RBI, | |
| SUM(b.SB) AS SB, | |
| 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 = 2014 | |
| AND AB >= 300 | |
| GROUP BY b.playerID | |
| HAVING HR >= 10 AND R >= 50 AND RBI >= 50 AND SB >= 10 | |
| ORDER BY SOPERC ASC; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment