MYSQL Replacement Time of Year Month Day Field Time Division and Second Constant Instance Analysis

  • 2021-08-28 21:24:14
  • OfStack

Writing 1:


update sas_order_supply_month_pay set 
RECEIVE_TIME=REPLACE(RECEIVE_TIME,DATE_FORMAT(RECEIVE_TIME,'%Y-%m-%d'),(select PERIOD_END from sas_task_supply_month_pay_period where belong='1729' 
and CREATE_TIME like '%2017-07-12%')) where ORDER_CODE='PO201707130115';

Writing 2:


update sas_order_supply_month_pay set 
RECEIVE_TIME= ADDTIME ((select PERIOD_END from sas_task_supply_month_pay_period where belong='1729' 
and CREATE_TIME like '%2017-07-12%')+interval 0 hour,time(RECEIVE_TIME)) where ORDER_CODE='PO201707130115';

Writing 3:


update sas_order_supply_month_pay set 
RECEIVE_TIME = concat((select PERIOD_END from sas_task_supply_month_pay_period where belong='1729' 
and CREATE_TIME like '%2017-07-12%'),' ',DATE_FORMAT(RECEIVE_TIME,'%H:%i:%S')) where ORDER_CODE='PO201707130115';

Description: s


as_order_supply_month_pay Tabular RECEIVE_TIME The field format is "2017-06-16 12:13:16" , sas_task_supply_month_pay_period Tabular PERIOD_END The field format is "2017-07-12",

After execution RECEIVE_TIME Modify to "2017-07-12 12:13:16" .

Wrong writing:


update sas_order_supply_month_pay set 
RECEIVE_TIME = DATE_FORMAT(concat((select PERIOD_END from sas_task_supply_month_pay_period where belong='1729' 
and CREATE_TIME like '%2017-07-12%'),' ',(select DATE_FORMAT(RECEIVE_TIME,'%H:%i:%S') from sas_order_supply_month_pay 
where ORDER_CODE='PO201707130115')),"yyyy-MM-dd %H:%i:%S") where ORDER_CODE='PO201707130115';

Wrong writing reports errors:


[Err] 1093 - You can't specify target table 'sas_order_supply_month_pay' for update in FROM clause

Error analysis:

Error statement:


(select DATE_FORMAT(RECEIVE_TIME,'%H:%i:%S') from sas_order_supply_month_pay where ORDER_CODE='PO201707130115')

This statement can be executed separately, but it can report errors when executed together. Guess: The modified table and subquery cannot be the same table?


Related articles: