我想加入 2 个表并根据第二个表的指定值更新第一个表的值。我使用其他解决方案失败了。
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
语法的更多信息,请访问以下链接:
https://www.postgresql.org/docs/current/static/sql-update.html
关于sql - 带有连接的 Postgresql 更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49530493/