THIS IS USING MYSQL
My question is the following. I have a baseball database, and in that baseball database there is a master table which lists every player that has ever played. There is also a batting table, which tracks every players’ batting statistics. I created a view to join those two together; hence the masterplusbatting table.
I now want to find the highest HR hitter in each decade since baseball began. Here is what I tried.
select f.yearID, truncate(f.yearid/10,0) as decade,f.nameFirst, f.nameLast, f.HR
from (
select yearID, max(HR) as HOMERS
from masterplusbatting group by yearID
)as x inner join masterplusbatting as f on f.yearID = x.yearId and f.HR = x.HOMERS
group by decade
You can see that I truncated the yearID in order to get 187, 188, 189 etc instead of 1897, 1885,. I then grouped by the decade, thinking that it would give me the highest per decade, but it is not returning the correct values. For example, it’s giving me Adrian Beltre with 48 HR’s in 2004 but everyone knows that Barry Bonds hit 73 HR in 2001. Can anyone give me some pointers?
Editted for MySQL