--SQLServer2000建立测试环境
set nocount on
create table logic (Value char(2))
insert into logic(value)
select('34')
union select('35')
union select('38')
union select('64')
union select('67')
union select('91')
union select('95')
union select('c1')
union select('c2')
union select('c8')
union select('c5')
--测试语句
--1、小明说:如果我不知道的话,小强肯定也不知道
delete from logic
where left(value,1) in(
select left(value,1) from logic a
where not exists (
select * from logic
where right(a.value,1)=right(value,1)
and value<>a.value
)
)
--2、小强说:本来我也不知道,但是现在我知道了
delete a from logic a
where exists(
select * from logic
where right(value,1)=right(a.value,1)
and value<>a.value)
--3、小明说:哦,那我也知道了
delete a from logic a
where exists(
select * from logic
where left(value,1)=left(a.value,1)
and value<>a.value)
select * from logic
--删除测试环境
drop table logic
set nocount off
--执行结果
/*--------------------------
Value
91
----------------------------*/