access 如何删除一列中显然是错误的数据?

来源:百度知道 编辑:UC知道 时间:2024/06/08 12:35:44
我有如下数据:
第一列 第二列
1 A
2 A
3 A
4 A
5 A
6 B
7 A
8 A
9 B
10 B
11 B
12 B
13 A
14 B
15 B
16 B
access能否把夹杂在一堆A里单独的那个B和一堆B里单独的那个A,连着他们前面的id自动删除掉。也就是,如果具备下列条件:
1,与上下数据都不相同的单独数据
2,如果上下行是空值,则与空值所在行的下一行或上一行都不相同的数据
就予以整行删除

麻烦达人们帮个忙,能把详细的步骤告诉我,因为初学,好多东西还不知道到哪里找呢。多谢啦!!
数据是不固定的,大多数情况下,数据会按超AAAAAAABBBBBBB的形式出现,但里面会有夹杂错误数据的情况,如AAABAAABBBABBB等。如果出现ABAB夹杂的情况,那就删除其中任何一个,删掉A保留B或删掉B保留A都可以。谢谢!!

在SQL Server 下测试通过:
先建立表
create table tablenew(
number int,
data varchar(10)
)
向表里输入测试数据:
1 A
2 A
3 B
4 A
5 A
6 B
7 B
8 B
9 A
10 B
11 B
12 B
13 A
14 B
15 A
然后建立视图:
Create view compare as
select a.number,a.data,b.data as next,c.data as prior
from tablenew a inner join tablenew b on a.number=b.number-1
inner join tablenew c on a.number=c.number+1
where a.number<>'1' and a.number <>'15'

运行语句建立视图成功后:
delete from tablenew where number in (
select number from compare
where data<>next and data<>prior
and number-1 not in (
select number from compare
where data<>next and data<>prior
)
)

select * from tablenew

结果:
1 A
2 A
4 A
5 A
6 B
7 B
8 B
10 B
11 B
12 B
14 B
15 A