我正在尝试编写一个join语句来将以下三个数据集连接在一起。(这是使用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)