《MYSQL教程MYSQL替换时间(年月日)字段时分秒不变实例解析》要点:
本文介绍了MYSQL教程MYSQL替换时间(年月日)字段时分秒不变实例解析,希望对您有用。如果有疑问,可以联系我们。
写法1:MYSQL应用
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';
写法2:MYSQL应用
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';
写法3:MYSQL应用
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';
说明: sMYSQL应用
as_order_supply_month_pay表的RECEIVE_TIME字段格式为"2017-06-16 12:13:16",sas_task_supply_month_pay_period表的PERIOD_END字段格式为"2017-07-12",
执行后RECEIVE_TIME
修改为"2017-07-12 12:13:16"
.MYSQL应用
错误写法:MYSQL应用
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';
错误写法报错:MYSQL应用
[Err] 1093 - You can't specify target table 'sas_order_supply_month_pay' for update in FROM clause
错误分析:MYSQL应用
错误语句:MYSQL应用
(select DATE_FORMAT(RECEIVE_TIME,'%H:%i:%S') from sas_order_supply_month_pay where ORDER_CODE='PO201707130115')
此语句单独执行是可以的,但是合在一起执行报错,猜测:修改表和子查询不能是同一个表?MYSQL应用
以上所述是小编给大家介绍的MYSQL替换时间(年月日)字段时分秒不变的实现办法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的.在此也非常感谢大家对维易PHP网站的支持!MYSQL应用
欢迎参与《MYSQL教程MYSQL替换时间(年月日)字段时分秒不变实例解析》讨论,分享您的想法,维易PHP学院为您提供专业教程。