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
欢迎大家阅读《mysql如何做关联更新》,跪求各位点评,by 搞代码
------解决方案--------------------
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
原创文章,转载请注明: 转载自搞代码
微信 赏一包辣条吧~
支付宝 赏一听可乐吧~