This is the original Oracle statement
The update TB_CLS_PROFIT_REPORT r
Set r.L AST_AMT=IFNULL ((select Arthur c. URR_AMT from TB_CLS_PROFIT_REPORT c where c.a. cct_Date=date_format (ADD_MONTHS (str_to_date (# {yearMonth, jdbcType=CHAR} '% % m Y'), 1), '% % m Y')), 0),
R.C HANGE_RATE=(r.C URR_AMT/decode (
(select IFNULL (Arthur c. URR_AMT from TB_CLS_PROFIT_REPORT c where c.a. cct_Date=date_format (ADD_MONTHS (str_to_date (# {yearMonth, jdbcType=CHAR} '% % m Y'), 1), '% % m Y')), r.C URR_AMT),
0,
R.C URR_AMT, IFNULL ((select Arthur c. URR_AMT from TB_CLS_PROFIT_REPORT c where c.a. cct_Date=date_format (ADD_MONTHS (str_to_date (# {yearMonth, jdbcType=CHAR} '% % m Y'), 1), '% % m Y')), r.C URR_AMT)))
Where state Richard armitage cct_Date=# {yearMonth, jdbcType=CHAR}
I changed to
The UPDATE TB_CLS_PROFIT_REPORT r
The SET r.C HANGE_RATE=(r.C URR_AMT/(case
When (SELECT Arthur c. URR_AMT FROM TB_CLS_PROFIT_REPORT c WHERE c.a. cct_Date=date_format (date_add (str_to_date (' 201511 ', '% % m Y'), the INTERVAL of 1 month), '% % m Y'))=0 then r.C URR_AMT
When (SELECT Arthur c. URR_AMT FROM TB_CLS_PROFIT_REPORT c WHERE c.a. cct_Date=date_format (date_add (str_to_date (' 201511 ', '% % m Y'), the INTERVAL of 1 month), '% % m Y')) is NULL then r.C URR_AMT
The else (select * FROM (select Arthur c. URR_AMT FROM TB_CLS_PROFIT_REPORT c WHERE c.a. cct_Date=date_format (date_add (str_to_date (' 201511 ', '% % m Y'), the INTERVAL of 1 month), '% % m Y')) TB)
END)
)
Where state Richard armitage cct_Date='201511'
Always an error (Err), 1093 - You can 't specify target table' r 'for update in the FROM clause
Table structure
/*
Navicat MySQL Data Transfer
The Source Server: 20170607
The Source Server Version: 50636
The Source Host: 172.168.65.26:3316
The Source Database: inetpay_clear
The Target Server Type: MYSQL
The Target Server Version: 50636
The File Encoding: 65001
Date: 2017-06-16 10:37:22
*/
The SET FOREIGN_KEY_CHECKS=0;
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
- Table structure for tb_cls_profit_report
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
DROP TABLE IF the EXISTS ` tb_cls_profit_report `;
The CREATE TABLE ` tb_cls_profit_report ` (
` ID ` varchar (36) NOT NULL,
` LAST_AMT ` decimal (18, 0) NOT NULL,
` CURR_AMT ` decimal (18, 0) NOT NULL,
` CHANGE_RATE ` decimal (5, 2) NOT NULL,
` ACCT_DATE ` char (8) NOT NULL,
` SUBJECT_ONE ` char (1) NOT NULL,
` SUBJECT_TWO ` char (4) NOT NULL,
` SUBJECT_THREE ` char (7) the NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
- Records of tb_cls_profit_report
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
My Internet as if to collect the alias but really don't know how