如果该表的year+number不唯一,则需要提供一个具有唯一值的字段或字段组。
现假设year,number唯一,sql语句写法如下:
select
a.[id] as IDA,b.[id] as IDB,a.[year] as YEARA,b.[year] as YEARB,
a.[number] as NumberA,b.[number] as NumberB,a.[text] as testA,b.[text] as testB
from [tab1] a , [tab1] b
where a.[year]=(select top 1 x.[year] from [tab1] x where x.[number]=b.[number] and x.[year]>=b.[year]-1 order by x.[year]) and a.[number]=b.[number]
and a.[year]!=b.[year]
order by a.[id]