Writing method 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 method 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 method 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: The format of the RECEIVE_TIME field in the as_order_supply_month_pay table is "2017-06-16 12:13:16", and the format of the PERIOD_END field in the sas_task_supply_month_pay_period table is "2017-07-12", After execution, Wrong way of 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 error: [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 individually, but an error occurs when it is executed together. My guess is: the modified table and the subquery cannot be the same table? The above is the implementation method of replacing the MYSQL time (year, month, day) field with unchanged hours, minutes and seconds introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website! You may also be interested in:
|
<<: How to simplify Redux with Redux Toolkit
>>: How to use Nginx to solve front-end cross-domain problems
1. What is master-slave replication? Master-slave...
Preface The requirement implemented in this artic...
WeChat applet uses scroll-view to achieve left-ri...
Table of contents 1. Array deduplication 2. Dedup...
<div id="root"> <h2>Keep go...
In the front-end and back-end separation developm...
Table of contents Preface: System Requirements: I...
Table of contents 1. What is reflection? 2. Refle...
Replication is to transfer the DDL and DML operat...
Table of contents 1. Download WeChat developer to...
In general : [1 important flag] > [4 special fl...
background I am learning nodejs recently, and I r...
Download source code git clone https://github.com...
Table of contents The first method: When the MySQ...
I have a server with multiple docker containers d...