PostgreSQL 怎么连表更新数据?

2021-09-01 11:05:54 浏览数 (3)

pg连表更新语法如下:

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

FROM
    数据来源表 cqt
WHERE
    要更新的表.bsm = cqt.bsm

实例:

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 人点赞