sql - SQL 连接 2 个表以查看差异
问题描述
我有 2 个要加入的表,以便轻松查看它们之间的差异,除以一列(类型)中指定的部分。举个例子:
表格1:
Type1|Data1
Type1|Data2
Type2|Data3
表2:
Type1|Data1
Type2|Data5
Type2|Data6
预期结果:
Type1|Data1|Type1|Data1
Type1|Data2|null|null
Type2|Data3|Type2|Data5
null |null|Type2|Data6
我怎样才能做到这一点?没有唯一标识符我可以绑定这些表
解决方案
我想你想枚举这些值,然后使用full join
:
select t1.type, t1.data, t2.type, t2.data
from (select t1.*, row_number() over (partition by type order by type) as seqnum
from t1
) t1 full join
(select t2.*, row_number() over (partition by type order by type) as seqnum
from t2
) t2
on t1.type = t2.type and t1.seqnum = t2.seqnum;
推荐阅读
- python - 基于标签的共现图像聚类
- c# - ASP.NET Core 3.0 端点路由不适用于默认路由
- gradle - 在 packageRunBuild Segmentation Fault 上 Gradle 构建失败
- python - C++ python模块(基于Pybind11)导入报错:ModuleNotFoundError
- javascript - 如何正确创建班级成员?
- c# - 如何在 .netcore-3.0 中测试标头属性?
- php - 为什么边缘不缓存图像
- cakephp - 如何获取包含子句以在 CakePHP 中生成正确的代码
- r - 如何模拟一个 100 人的班级?
- javascript - 如何使用具有不透明响应的 API?