SQL完全外部联接 [英] SQL Full Outer Join

查看:111
本文介绍了SQL完全外部联接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个join语句以将以下三个数据集连接在一起. (这是使用MS SQL Server)

I am trying to write a join statement to join the following three data sets together. (This is using 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       

我认为完全外部联接可以做到这一点,但是我遇到了主要的跨产品问题.

I think a full outer join is able to do this but I am running into major cross product issues.

推荐答案

尝试一下:

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)

这篇关于SQL完全外部联接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆