我正在尝试编写一个连接语句将以下三个数据集连接在一起。 (这是使用 MS SQL Server)
Set 1
ID Date Col1
1 Jan 11 a1
1 Jan 13 a2
Set 2
ID Date Col2
1 Jan 11 b1
1 Jan 15 b2
Set 3
ID Date Col3
1 Jan 15 c1
1 Jan 17 c2
Combined Set
ID Date Col1 Col2 Col3
1 Jan 11 a1 b1
1 Jan 13 a2
1 Jan 15 b2 c1
1 Jan 17 c2
我认为完整的外部连接能够做到这一点,但我遇到了主要的跨产品问题。
尝试一下:
select coalesce(t1.date, t2.date, t3.date) date, col1, col2, col3 from table1 t1
full outer join table2 t2 on (t1.date = t2.date)
full outer join table3 t3 on (t2.date = t3.date)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)