postgresql – 带连接的Redshift表更新

前端之家收集整理的这篇文章主要介绍了postgresql – 带连接的Redshift表更新前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有3个表t1,t2和t3.
t1有2列 – > id1,val1
t2 -> id2,val2  
t3 -> id3,val3  
If id1=id2 and id2 = id3

然后我需要更新val1 ad val3.
但我重复id1,每个都应该有相同的val3

我在用

update  t1
inner join  t2 on t1.id1 = t2.id2
inner join  t3 on t2.id2 = t3.id3
set t1.val1 =  t3.val3
;

但是不能这样做.

正确的语法是:

UPDATE table_name SET column = { expression | DEFAULT } [,…]
[ FROM fromlist ]
[ WHERE condition ]

所以你的UPDATE语句应该如下所示:

update t1 set val1 = val3
from t2 inner join t3 on t2.id2 = t3.id3
where t1.id1 = t2.id2
;

请参阅Redshift documentation及其综合UPDATE examples.

原文链接:https://www.f2er.com/postgresql/238875.html

猜你在找的Postgre SQL相关文章