解决重复项的一种可能的解决方案是创建一个子查询,该子查询对两个表执行UNIOn,并通过对所有列进行分组来包括每个表中包含的重复项数量。然后,外部查询可以对所有列进行分组,包括行计数列。如果表匹配,则不应返回任何行:
create table employees (name varchar2(100));create table employees_hist (name varchar2(100));insert into employees values ('Jack Crack');insert into employees values ('Jack Crack');insert into employees values ('Jill Hill');insert into employees_hist values ('Jack Crack');insert into employees_hist values ('Jill Hill');insert into employees_hist values ('Jill Hill');with both_tables as(select name, count(*) as row_count from employees group by nameunion all select name, count(*) as row_count from employees_hist group by name)select name, row_count from both_tablesgroup by name, row_count having count(*) <> 2;给你:
Name Row_countJack Crack 1Jack Crack 2Jill Hill 1Jill Hill 2
这告诉您两个名称在一个表中出现一次,在另一个表中出现两次,因此表不匹配。



