我就废话不多说了,大家还是直接看代码吧~
1
2
3
4
5
6
7
|
补充:Postgresql 连表更新字段语法 update
下面这段sql本来目的是想更新条件下的数据,可是这段sql却更新了整个表的数据。sql如下:
1
2
3
4
5
6
7
8
9
10
11
12
|
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' ) |
正确的写法有多种,如下方法也能够实现正确的数据库修改:
1
2
3
4
5
6
7
8
9
10
11
|
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' ) |
以上为个人经验,希望能给大家一个参考,也希望大家多多支持服务器之家。如有错误或未考虑完全的地方,望不吝赐教。
原文链接:https://www.cnblogs.com/SeNaiTes/p/11447935.html