A表
姓名 低保证号
张三 001
李四 002
李七 002
王五 003
赵九 004
杨十 002
杨二 005
B表
户主 成员 低保证号
张三 张三 001
张三 张六 001
李四 李四 002
李四 李七 002
王五 王五 003
王五 王八 003
杨一 杨一 005
杨一 杨二 005
1、A表低保证号在B表不存在的数据
赵九 004
2、A表低保证号在B表存在,但是姓名不符的数据(证号相同,但是户主、成员均不符)
杨十 002
3、A表低保证号在B表存在,并且低保证号重复的数据(杨十 002属于姓名不符这类)
李四 002
李七 002
4、正确的数据(低保证号,姓名与户主或者成员一致的数据)
张三 001
王五 003
杨二 005
也不知道说明白没有。
------解决方案--------------------
create table #ta(姓名 varchar(10),低保证号 varchar(10))
insert into #ta
select '张三','001'
union all select '李四','002'
union all select '李七','002'
union all select '王五','003'
union all select '赵九','004'
union all select '杨十','002'
union all select '杨二','005'
create table #tb(姓名 varchar(10),成员 varchar(10),低保证号 varchar(10))
insert into #tb
select '张三','张三','001'
union all select '张三','张六','001'
union all select '李四','李四','002'
union all select '李四','李七','002'
union all select '王五','王五','003'
union all select '王五','王八','003'
union all select '杨一','杨一','005'
union all select '杨一','杨二','005'
--问题1.
select *
from #ta a
where not exists(select 1 from #tb b where a.低保证号=b.低保证号)
/*
赵九 004
*/
--问题2.
select *
from #ta a
where not exists(select 1 from #tb b where a.低保证号=b.低保证号 and a.姓名=b.成员)