时间:2021-05-23
写法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';写法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';写法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';说明: s
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"。
错误写法:
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';错误写法报错:
[Err] 1093 - You can't specify target table 'sas_order_supply_month_pay' for update in FROM clause错误分析:
错误语句:
(select DATE_FORMAT(RECEIVE_TIME,'%H:%i:%S') from sas_order_supply_month_pay where ORDER_CODE='PO201707130115')此语句单独执行是可以的,但是合在一起执行报错,猜测:修改表和子查询不能是同一个表?
以上所述是小编给大家介绍的MYSQL替换时间(年月日)字段时分秒不变的实现方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
一、简介编写一个会动的日历,日历上面有年月日,周几,时分秒,效果如下:年月日,周几,时分秒都会随着系统时间的走动而改变二、代码Document*{margin:
1、获取当前年月日时分秒#-*-encoding=utf-8-*-importdatetimenow=datetime.datetime.now()print(
基本操作01:获取当前时间dateTime:=time.Now()fmt.Println(dateTime)02:获取年月日时分秒纳秒year:=time.No
1.获取当前时间varmyDate=newDate();2.获取时间中的年月日时分秒myDate.getYear();//获取当前年份(2位)myDate.ge
--DateTime数字型System.DateTimecurrentTime=newSystem.DateTime();1.1取当前年月日时分秒current