写法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';
說明: sas_order_supply_month_pay表的RECEIVE_TIME欄位格式為"2017-06-16 12:13:16",sas_task_s017-06-16 12:13:16",sas_task_s_perwly_yper_w找到,sas_t表格的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取代時間欄位且時分秒不變的方法的詳細內容。更多資訊請關注PHP中文網其他相關文章!