MYSQL replaces the time (year, month, day) field with unchanged hours, minutes, and seconds. Example analysis

MYSQL replaces the time (year, month, day) field with unchanged hours, minutes, and seconds. Example analysis

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, RECEIVE_TIME is changed to "2017-07-12 12:13:16" .

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:
  • Explanation of whether MySQL time fields use INT or DateTime

<<:  How to simplify Redux with Redux Toolkit

>>:  How to use Nginx to solve front-end cross-domain problems

Recommend

Example of using MySQL to count the number of different values ​​in a column

Preface The requirement implemented in this artic...

WeChat applet scroll-view realizes left-right linkage effect

WeChat applet uses scroll-view to achieve left-ri...

Detailed explanation of JavaScript array deduplication

Table of contents 1. Array deduplication 2. Dedup...

Cross-domain issues in front-end and back-end separation of Vue+SpringBoot

In the front-end and back-end separation developm...

Detailed tutorial on installing Docker on CentOS 8.4

Table of contents Preface: System Requirements: I...

Reflection and Proxy in Front-end JavaScript

Table of contents 1. What is reflection? 2. Refle...

MySQL replication advantages and principles explained in detail

Replication is to transfer the DDL and DML operat...

How to create WeChat games with CocosCreator

Table of contents 1. Download WeChat developer to...

Discussion on CSS style priority and cascading order

In general : [1 important flag] > [4 special fl...

How to configure MySQL on Ubuntu 16.04 server and enable remote connection

background I am learning nodejs recently, and I r...

GDB debugging MySQL actual combat source code compilation and installation

Download source code git clone https://github.com...

Several methods to execute sql files under mysql command line

Table of contents The first method: When the MySQ...

How to deal with too many Docker logs causing the disk to fill up

I have a server with multiple docker containers d...