带有联接的Postgresql更新 [英] Postgresql Update with join

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

问题描述

我想加入2个表并在第2个表的指定值上更新firts表的值.我使用其他解决方案失败.

I want to join 2 tables and update value of firts table on specified value of 2nd table. I failed using others solutions.

UPDATE customers
SET cutoffstop = cutoffstop + '432000'
FROM customers as c
JOIN bluemedia as b ON c.id = b.customerid
WHERE b.orderid = '217201807'

推荐答案

常规更新语法:

[ WITH [ RECURSIVE ] with_query [, ...] ]
UPDATE [ ONLY ] table [ [ AS ] alias ]
    SET { column = { expression | DEFAULT } |
          ( column [, ...] ) = ( { expression | DEFAULT } [, ...] ) } [, ...]
    [ FROM from_list ]
    [ WHERE condition | WHERE CURRENT OF cursor_name ]
    [ RETURNING * | output_expression [ [ AS ] output_name ] [, ...] ]

为您解决的问题:

UPDATE customers AS c
SET cutoffstop = cutoffstop + 432000
FROM bluemedia as b
WHERE c.id = b.customerid
AND b.orderid = '217201807'

有关UPDATE语法的更多信息,请点击以下链接:

For more information on UPDATE syntax follow the below link:

https://www.postgresql.org/docs/current/static/sql-update.html

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

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