SQL的UPDATE联查更新语句,开始想都没想就要这样做,然后语法出了上网查了下,还真有,以前没这样试过,记录一下方便回忆
1
2
3
4
5
6
7
|
Update
a
set
a.Manage_FunctID=b.Manage_FunctID
From
Manage_PageUrl a
Left
join
Manage_ButtonBar b
on
a.Manage_PageUrlID=b.Manage_PageUrlID
Left
join
Manage_Funct c
on
b.Manage_FunctID=c.Manage_FunctID
|
============================华丽的分割线 试了一下午 上面的sql 在mysql 下不好用=========================================
正确的sql代码是:
update t_b as b right join (select sum(data) as c,p_id from t_a group by p_id) as a on b.p_id=a.p_id set b.data=b.data-a.c
update 表名(在这一位做集合/连表) set 更新值=集合中某一项 where 条件
update act_year_end aye LEFT JOIN psum abc on aye.uid =abc.uid set aye.prizeNumber = abc.pnum, aye.prizeProfit = abc.psum