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

使用另外一個表更新記錄

有時候咱們的數據不會當即去更新,而是存在另一張表中等待更新,這是在平常開發中常見的操做。mysql

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 能夠下面這樣:sql

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
)

合併記錄

資料整理中,過多資料,思路正在路上。code

相關文章
相關標籤/搜索