UPDATE jobhist SET (job, sal ) = ( SELECT job, sal + 50 FROM emp WHERE ename='ALLEN' );
如果是 9.4 的話,可以用 Common Table Expression 達成
WITH cte AS ( SELECT job, sal FROM emp WHERE ename='ALLEN' ) UPDATE jobhist j SET j.job = cte.job, j.sal = cte.sal + 50 FROM cte;
最近被被問到,就紀錄一下~
參考
sql - update multiple column in table using same table data in postgres? - Stack Overflow
艾力克斯札記: EnterpriseDB Oracle Compatibility 分享 (3) - update multiple columns
沒有留言:
張貼留言