例如:
name | startyear | endyear
jon 2003 2005
jake 1999 2002
blake 1997 1998
jake 1995 1996
jason 1993 1994
有没有办法回报布莱克?
我想知道杰克这两个词之间的掌柜是谁。
答案 0 :(得分:2)
您可以使用between
,例如:
select yt.name
from YourTable yt
where TheYear between yt.startyear and yt.endyear
between
是包容性的,所以这将使Blake为TheYear = 97和98。
答案 1 :(得分:2)
如果没有更多信息,这是我能给出的最佳建议:
SELECT name FROM your_table WHERE startyear > (SELECT min(endyear) FROM your_table WHERE name = 'jake') AND endyear < (SELECT max(startyear) FROM your_table WHERE name = 'jake')