first X number of career years

21 views
Skip to first unread message

Matt Bandi

unread,
Jul 1, 2014, 2:37:00 PM7/1/14
to baseball-sq...@googlegroups.com
Does anyone know a command I could use to query the first X number of career seasons for all players? For example, let's say I wanted to use Baseball Databank database to find the all-time leaders in home runs during a player's first three years in the majors, or something like that.

Thanks for any suggestions. 

Daniel Hirsch

unread,
Jul 1, 2014, 2:58:11 PM7/1/14
to Matt Bandi, baseball-sq...@googlegroups.com
Matt,

I would try this..

SELECT Batting.playerID, SUM(HR) AS HR FROM Batting LEFT JOIN (SELECT playerID, MIN(yearID) AS first FROM Batting GROUP BY playerID) AS z ON (Batting.playerID = z.playerID) WHERE Batting.yearID < z.first + 10 GROUP BY Batting.playerID ORDER BY HR DESC

Dan Hirsch

Matt Bandi

unread,
Jul 2, 2014, 9:49:49 PM7/2/14
to baseball-sq...@googlegroups.com, matt...@gmail.com
Worked perfectly. Thanks so much for your help.
Reply all
Reply to author
Forward
0 new messages