App下載

PostgreSQL 怎么連表更新數(shù)據(jù)?

拖延俱樂(lè)部 2021-09-01 11:05:54 瀏覽數(shù) (6355)
反饋

pg連表更新語(yǔ)法如下:

UPDATE 要更新的表
SET 字段1 = cqt.字段1,
 字段2 = cqt.字段2,

FROM
    數(shù)據(jù)來(lái)源表 cqt
WHERE
    要更新的表.bsm = cqt.bsm

實(shí)例:

update table_p as p 
set p_name = a.name,p_user = a.user_id,p_type = 'P02'
from (
select x.user_id,x.name,x.p_id from table_u x
join table_p y on x.p_id = y.p_id
) as a where p.p_id = a.p_id;


0 人點(diǎn)贊