/ 中存储网

MySQL数据库的update from 子查询使用方法

2014-07-13 16:22:07 来源:中存储网

mssql 子查询更新

update log set uin= b.uin
from log a,logs b
where a.accountuin = b.accountuin

mysql 不支持 update 子查询更新

找了半天资料 终于搞定了...

update `log` a inner join `logs` b on a.`accountuin` = b.`accountuin`
set a.`uin` = b.`uin` where a.`accountuin` = b.`accountuin`

这样就能 将查询出来的字段批量更新过去了...

String sql="update jf_wares w INNER JOIN jf_order_detail od ON od.wares_id=w.wares_id  set w.surplus_num=IF(w.surplus_num>od.buy_count,w.surplus_num-od.buy_count,0) where od.order_id=? ";