日期:2014-05-16  浏览次数:20883 次

mysql怎么做关联更新?
SQL code

update  a set a.discount = b.adjust_fee from  tm_order_info  a INNER JOIN
(
select order_sn,sum(adjust_fee) adjust_fee  from tm_order_goods  where   order_sn in('20120224-725029049' ,'20120309-735313946','20120304-731334448','20120312-738124285','20120315-739599869',
'20120315-740373841','20120316-741076263','20120308-734709036','20120316-741041930','20120308-734400252','20120314-739698366','20120324-748335914',
'20120326-749938179','20120319-743458941','20120326-750145173','20120319-743636576','20120325-749622020','20120316-741414890','20120331-754313444','20120325-749134947','20120320-744278223'
)GROUP BY order_sn
)b on a.order_sn=b.order_sn
语法错误  应该怎么改?
[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from  tm_order_info  a INNER JOIN
(
select order_sn,sum(adjust_fee) adjust_fee' at line 1




------解决方案--------------------
update tm_order_info a INNER JOIN
(
select order_sn,sum(adjust_fee) adjust_fee from tm_order_goods where order_sn in('20120224-725029049' ,'20120309-735313946','20120304-731334448','20120312-738124285','20120315-739599869',
'20120315-740373841','20120316-741076263','20120308-734709036','20120316-741041930','20120308-734400252','20120314-739698366','20120324-748335914',
'20120326-749938179','20120319-743458941','20120326-750145173','20120319-743636576','20120325-749622020','20120316-741414890','20120331-754313444','20120325-749134947','20120320-744278223'
)GROUP BY order_sn)b on a.order_sn=b.order_sn

set a.discount = b.adjust_fee
------解决方案--------------------
update tm_order_info a INNER JOIN
(
select order_sn,sum(adjust_fee) adjust_fee from tm_order_goods where order_sn in('20120224-725029049' ,'20120309-735313946','20120304-731334448','20120312-738124285','20120315-739599869',
'20120315-740373841','20120316-741076263','20120308-734709036','20120316-741041930','20120308-734400252','20120314-739698366','20120324-748335914',
'20120326-749938179','20120319-743458941','20120326-750145173','20120319-743636576','20120325-749622020','20120316-741414890','20120331-754313444','20120325-749134947','20120320-744278223'
)GROUP BY order_sn
)b on a.order_sn=b.order_sn
set a.discount = b.adjust_fee