App下載

PostgreSQL 怎么連表更新數據?

拖延俱樂部 2021-09-01 11:05:54 瀏覽數 (6823)
反饋

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 人點贊