如何排除不连续编号的行

怎么排除不连续编号的行?
怎么排除不连续编号的行?
编号         姓名

1              张三
2              张三
5              张三
8              李四
11            李四
12            李四
2              王五


只保留张三的1,2,李四的11,12,要怎么写啊?求助


------解决思路----------------------
;
with tm (编号,姓名) as
(
select 1,'张三' union all
select 2,'张三' union all
select 5,'张三' union all
select 8,'李四' union all
select 11,'李四' union all
select 12,'李四' union all
select 2,'王五'
)
select a.* from tm a,tm b where (a.编号-b.编号=1 or b.编号-a.编号=1) and a.姓名=b.姓名

------解决思路----------------------
引用:
;
with tm (编号,姓名) as
(
select 1,'张三' union all
select 2,'张三' union all
select 5,'张三' union all
select 8,'李四' union all
select 11,'李四' union all
select 12,'李四' union all
select 2,'王五'
)
select a.* from tm a,tm b where (a.编号-b.编号=1 or b.编号-a.编号=1) and a.姓名=b.姓名

with tm (编号,姓名) as
(
select 1,'张三' union all
select 2,'张三' union all
select 5,'张三' union all
select 8,'李四' union all
select 11,'李四' union all
select 12,'李四' union all
select 2,'王五'
)
select a.* from tm a,tm b where abs(a.编号-b.编号)=1 and a.姓名=b.姓名

------解决思路----------------------

create table #t(编号 int,姓名 varchar(10))

insert into #t
  select 1,'张三' union all
  select 2,'张三' union all
  select 5,'张三' union all
  select 8,'李四' union all
  select 11,'李四' union all
  select 12,'李四' union all
  select 2,'王五'


-- 删除
delete a
 from #t a
 where not exists(select 1 
                             from #t b 
                             where b.姓名=a.姓名 
                             and (b.编号=a.编号+1 or b.编号=a.编号-1))


-- 结果
select * from #t

/*
编号          姓名
----------- ----------
1           张三
2           张三
11          李四
12          李四

(4 row(s) affected)
*/

------解决思路----------------------
引用:
Quote: 引用:

;
with tm (编号,姓名) as
(
select 1,'张三' union all
select 2,'张三' union all
select 5,'张三' union all
select 8,'李四' union all
select 11,'李四' union all
select 12,'李四' union all
select 2,'王五'
)
select a.* from tm a,tm b where (a.编号-b.编号=1 or b.编号-a.编号=1) and a.姓名=b.姓名

with tm (编号,姓名) as
(
select 1,'张三' union all
select 2,'张三' union all
select 5,'张三' union all
select 8,'李四' union all
select 11,'李四' union all
select 12,'李四' union all
select 2,'王五'
)
select a.* from tm a,tm b where abs(a.编号-b.编号)=1 and a.姓名=b.姓名


结果去下重复