create Table Team(
Team nvarchar(10),
Year int
)

insert Team
select '活塞','1990'
union all
select '公牛','1991'
union all
select '公牛','1992'
union all
select '公牛','1993'
union all
select '火箭','1994'
union all
select '火箭','1995'
union all
select '公牛','1996'
union all
select '公牛','1997'
union all
select '公牛','1998'
union all
select '马刺','1999'
union all
select '湖人','2000'
union all
select '湖人','2001'
union all
select '湖人','2002'
union all
select '马刺','2003'
union all
select '活塞','2004'
union all
select '马刺','2005'
union all
select '热火','2006'
union all
select '马刺','2007'
union all
select '凯尔特人','2008'
union all
select '湖人','2009'
union all
select '湖人','2010'
select [Team],MIN(year) as [Begin],MAX(year) as [End] from (
select *,ROW_NUMBER() over(partition by team order by year) as rid from Team
) as a group by team,(YEAR-rid) having MAX(year)!=MIN(YEAR)
order by MIN(year)

 

 posted on 2018-04-26 21:44  会飞的金鱼  阅读(180)  评论(0)    收藏  举报