我就廢話不多說(shuō)了,大家還是直接看代碼吧~
UPDATE 要更新的表
SET 字段1 = cqt.字段1,
字段2 = cqt.字段2,
FROM
數(shù)據(jù)來(lái)源表 cqt
WHERE
要更新的表.bsm = cqt.bsm
補(bǔ)充:Postgresql 連表更新字段語(yǔ)法 update
下面這段sql本來(lái)目的是想更新條件下的數(shù)據(jù),可是這段sql卻更新了整個(gè)表的數(shù)據(jù)。sql如下:
UPDATE tops_visa.visa_order
SET op_audit_abort_pass_date = now()
FROM
tops_visa.visa_order as t1
INNER JOIN tops_visa.visa_visitor as t2
ON t1. ID = t2.order_id
WHERE
t1.op_audit_abort_pass_date IS NULL
AND (
t2. STATE = 'pch_abort_op_audit_pass'
OR t2. STATE = 'pvd_abort_op_audit_pass'
)
正確的寫法有多種,如下方法也能夠?qū)崿F(xiàn)正確的數(shù)據(jù)庫(kù)修改:
UPDATE tops_visa.visa_order as t1
SET op_audit_abort_pass_date = now()
FROM
tops_visa.visa_visitor AS t2
WHERE
t1.ID = t2.order_id
AND t1.op_audit_abort_pass_date IS NULL
AND (
t2. STATE = 'pch_abort_op_audit_pass'
OR t2. STATE = 'pvd_abort_op_audit_pass'
)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教。
您可能感興趣的文章:- sqoop讀取postgresql數(shù)據(jù)庫(kù)表格導(dǎo)入到hdfs中的實(shí)現(xiàn)
- sqoop 實(shí)現(xiàn)將postgresql表導(dǎo)入hive表
- Postgresql - 查看鎖表信息的實(shí)現(xiàn)
- 基于postgresql數(shù)據(jù)庫(kù)鎖表問(wèn)題的解決
- Postgresql鎖機(jī)制詳解(表鎖和行鎖)
- postgreSQL數(shù)據(jù)庫(kù) 實(shí)現(xiàn)向表中快速插入1000000條數(shù)據(jù)