Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 需要找出表之间的差异_Sql_Database_Rdbms - Fatal编程技术网

Sql 需要找出表之间的差异

Sql 需要找出表之间的差异,sql,database,rdbms,Sql,Database,Rdbms,我的表格结构如下: 我需要找出两个表之间的差异,即哪些数据在另一个表中不可用,反之亦然。 我可以找到如下差异: 使用的Sql查询: 预期成果: 我尝试了很多方法来提取数据,但我做不到! 非常感谢你的帮助。谢谢两件事:1.完全外部连接;2枚举具有相同值的行: select * from (select input_name_id, match_id, name, row_number() over (partition by input_name_id, match

我的表格结构如下:

我需要找出两个表之间的差异,即哪些数据在另一个表中不可用,反之亦然。 我可以找到如下差异:

使用的Sql查询: 预期成果: 我尝试了很多方法来提取数据,但我做不到!
非常感谢你的帮助。谢谢

两件事:1.完全外部连接;2枚举具有相同值的行:

select * 
from (select input_name_id, match_id, name, 
             row_number() over (partition by input_name_id, match_id, name order by name) as seqnum
      from Table1
     ) a full join 
     (select input_name_id, match_id, name, 
             row_number() over (partition by input_name_id, match_id, name order by name) as seqnum
      from Table2
     ) b
     on a.input_name_id = b.input_name_id and
        a.match_id = b.match_id and
        a.name = b.name and
        a.seqnum = b.seqnum
where a.seqnum is null or b.seqnum is null;
使用except和union all的简单解决方案


我删除了不兼容的数据库标记。请标记您真正使用的数据库。
select * 
from (select input_name_id, match_id, name, 
             row_number() over (partition by input_name_id, match_id, name order by name) as seqnum
      from Table1
     ) a full join 
     (select input_name_id, match_id, name, 
             row_number() over (partition by input_name_id, match_id, name order by name) as seqnum
      from Table2
     ) b
     on a.input_name_id = b.input_name_id and
        a.match_id = b.match_id and
        a.name = b.name and
        a.seqnum = b.seqnum
where a.seqnum is null or b.seqnum is null;
select null as a_input_name_id, null as a_matchid, null as a_name, input_name_id as b_input_name_id, matchid as b_matchid, name as b_name
from
(select input_name_id, matchid, name, row_number() over (partition by input_name_id, matchid, name order by input_name_id) as rw_num
from t2
except
select input_name_id, matchid, name, row_number() over (partition by input_name_id, matchid, name order by input_name_id) as rw_num
from t1 ) a


union all

select input_name_id as a_input_name_id, matchid as a_matchid, name as a_name, null as b_input_name_id, null as b_matchid, null as b_name
from
(select input_name_id, matchid, name, row_number() over (partition by input_name_id, matchid, name order by input_name_id) as rw_num
from t1
except
select input_name_id, matchid, name, row_number() over (partition by input_name_id, matchid, name order by input_name_id) as rw_num
from t2) b