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

Summary of common Nginx techniques and examples

1. Priority of multiple servers For example, if e...

Pure CSS3 realizes the effect of div entering and exiting in order

This article mainly introduces the effect of div ...

Share 5 helpful CSS selectors to enrich your CSS experience

With a lot of CSS experience as a web designer, we...

Record of the actual process of packaging and deployment of Vue project

Table of contents Preface 1. Preparation - Server...

Summary of some practical little magic in Vue practice

How can you forget lazy loading of routes that al...

MySQL 8.0 can now handle JSON

Table of contents 1. Brief Overview 2. JSON basic...

Table paging function implemented by Vue2.0+ElementUI+PageHelper

Preface I have been working on some front-end pro...

mysql creates root users and ordinary users and modify and delete functions

Method 1: Use the SET PASSWORD command mysql -u r...

Understanding and using React useEffect

Table of contents Avoid repetitive rendering loop...

Detailed tutorial on building Gitlab server on CentOS8.1

There is no need to say much about the difference...

Web Design Tutorial (2): On Imitation and Plagiarism

<br />In the previous article, I introduced ...