日期:2014-05-18 浏览次数:20417 次
--> --> (Roy)生成測試數據 declare @T table([A] int,[B] int,[C] int) Insert @T select 1,2,3 union all select 1,2,4 union all select 2,1,1 union all select 2,1,2 union all select 2,1,3 ;with a as ( Select *,ROW_NUMBER()over(order by (select 1)) as d from @T ) select a.A,a.B,a.C,[d]=Case when b.A Is not null then 'Y' else '' end from a left join a as b on a.d=b.d+1 and a.a=b.a and a.b=b.b /* A B C d 1 2 3 1 2 4 Y 2 1 1 2 1 2 Y 2 1 3 Y */