mysql操作目标表

来源:互联网 发布:python netsnmp 编辑:程序博客网 时间:2024/06/03 14:46
mysql中You can't specify target table for update in FROM clause错误的意思是说,不能先select出同一表中的某些值,再update这个表(在同一语句中)。 例如下面这个sql:
update  market_data.curves  set id_calendar = 'Bond_CN' where id_curve in(SELECT id_curve FROM market_data.curves where  cd_curve_type = 'IR_Bond'and id_curve not like 'IR_Bond_CNY_FIX_EX_GOV_SPT') ;


将select出的结果再通过中间表select一遍,这样就规避了错误。

update  market_data.curves  set id_calendar = 'Bond_CN' where id_curve in(select id_curve from (SELECT id_curve FROM market_data.curves where  cd_curve_type = 'IR_Bond'and id_curve not like 'IR_Bond_CNY_FIX_EX_GOV_SPT') a);


0 0
原创粉丝点击