辽宁品牌建设促进会 网站,免费个人网页空间ftp,建设部造价工程师考试网站,网站创建时间查询背景#xff1a;实际开发中需要用到全关联的用法#xff0c;之前没遇到过#xff0c;现在记录一下。需求是找到两张表的并集。
全关联的解释如下#xff1b; 下面建两张表进行测试
test_a表的数据如下 test_b表的数据如下#xff1b;
写第一个full join 的SQL进行查询…背景实际开发中需要用到全关联的用法之前没遇到过现在记录一下。需求是找到两张表的并集。
全关联的解释如下 下面建两张表进行测试
test_a表的数据如下 test_b表的数据如下
写第一个full join 的SQL进行查询测试
select * from pdata_dynamic.test_a a
full joinpdata_dynamic.test_b b
on a.idb.id;查询结果显示如下 把两个表的结果拼在一行了匹配不上的都用NULL值进行填充了显然不是我要的结果
优化好的full join的SQL写法如下
select
case whena.id is null then b.id
elsea.id
endid ,
case whena.name is null then b.name
elsea.name
endname,
case whena.age is null then b.age
elsea.age
endage,
case whena.hight is null then b.hight
elsea.hight
endhight
frompdata_dynamic.test_a a
full joinpdata_dynamic.test_b b
on a.idb.id;查询完显示如下nice