seq h 1 譴覿襯1 2 覿襯1 3 覿襯2 4 覿襯3 5 譴覿襯2 6 覿襯4 7 譴覿襯3 8 覿襯5
seq h 2 覿襯1 3 覿襯2 4 覿襯3 1 譴覿襯1 6 覿襯4 5 譴覿襯2 8 覿襯5 7 譴覿襯3--讌覓 豢豌: http://www.sqler.com/bSQLQA/745455
select 1 seq, '譴覿襯1' h into #temp union all select 2, '覿襯1' union all select 3, '覿襯2' union all select 4, '覿襯3' union all select 5, '譴覿襯2' union all select 6, '覿襯4' union all select 7, '譴覿襯3' union all select 8, '覿襯5'
;with new_idx as ( select h , seq , isnull(lead(seq, 1) over(order by seq), 99999) - 0.5 new_seq from #temp where h like '譴%' ) select a.seq , a.h from #temp a left join new_idx b on a.seq = b.seq order by isnull(b.new_seq, a.seq)