使用联接更新Redshift表 [英] Redshift table update with join
本文介绍了使用联接更新Redshift表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有3个表t1,t2和t3.
t1有2列-> id1,val1
I have 3 table t1, t2 and t3.
t1 has 2 column-> id1, val1
t2 -> id2, val2
t3 -> id3, val3
If id1=id2 and id2 = id3
然后我需要更新val1和val3. 但是我重复了id1,每个都应该有相同的val3
then I need to update val1 ad val3. But I have repeating id1 and each should have same val3
我正在使用
update t1
inner join t2 on t1.id1 = t2.id2
inner join t3 on t2.id2 = t3.id3
set t1.val1 = t3.val3
;
但无法做到这一点.
推荐答案
正确的语法是:
更新表名 SET列= {表达式 |默认} [,...]
[FROM fromlist ]
[条件 ]
UPDATE table_name SET column = { expression | DEFAULT } [,...]
[ FROM fromlist ]
[ WHERE condition ]
因此,您的UPDATE
语句应如下所示:
So your UPDATE
statement should look as follows:
update t1 set val1 = val3
from t2 inner join t3 on t2.id2 = t3.id3
where t1.id1 = t2.id2
;
请参见 Redshift文档及其全面的 UPDATE
示例.
See the Redshift documentation and their comprehensive UPDATE
examples.
这篇关于使用联接更新Redshift表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文