明らかに、あなたは雇用保障技術を使いたいと思っています。
with
t11(r, c, num) as (SELECT 1, 1, num from table11),
t12(r, c, num) as (SELECT 1, 2, num from table12),
t21(r, c, num) as (SELECT 2, 1, num from table21),
t22(r, c, num) as (SELECT 2, 2, num from table22)
select
coalesce(t11.num, t21.num) as col1,
coalesce(t12.num, t22.num) as col2
from
(t11 cross join t12)
full outer join
(t21 cross join t22)
on t11.r = t21.r or t12.r = t22.r
または、列 c の値を無駄にしたくない場合は、これの方がよい場合があります。
case
when t11.r * t11.c = t12.c - t12.r
then t11.num else t21.num
end as col1,
case
when t21.r * t22.r * t22.c - t21.c = t21.r + t21.c + t22.r + t22.c
then t22.num else t12.num
end as col2