I have a database of baseball stats, one record per player per year, and I want to generate a list of players that meet certain criteria two years in a row. But I'm running into issues with players getting doubled up when they meet the criteria for more than two years.
The core structure looks something like this:
select PLAYER
from
TABLE a,
TABLE b
where a.YEAR = b.YEAR+1
But when a player meets the criteria for two pairs of years, like this...
Player A | 2011 | 2012
Player A | 2012 | 2013
... you wind up doubling him up. In this instance, his 2012 season would get counted twice. I'd want the Player to be on my list as such:
Player A | 2011
Player A | 2012
Player A | 2013
...but right now I'm getting:
Player A | 2011
Player A | 2012
Player A | 2012
Player A | 2013
Can anyone provide a solution for only including that middle year once?