sql 语句系列(更新系列)[八百章之第六章]

使用另一个表更新记录

有时候我们的数据不会立即去更新,而是存在另外一张表中等待更新,这是在日常开发中常见的操作。

update e 
set e.SAL=ns.SAL+e.SAL,
e.COMM=ns.SAL
from emp e,new_sal ns
where e.EMPNO=ns.EMPNO

mysql 可以下面这样:

update emp e  set (e.SAL,e.COMM)=(select e.SAL+ns.SAL,ns.SAL from new_sal ns where ns.EMPNO=e.EMPNO)
where exists (
select null
from  new_sal ns
where ns.EMPNO=e.EMPNO
)

合并记录

资料整理中,过多资料,思路正在路上。

posted @ 2020-03-24 23:37  敖毛毛  阅读(120)  评论(0编辑  收藏  举报