用MYSQL替換時(shí)間字段且時(shí)分秒不變的方法
發(fā)表時(shí)間:2023-07-26 來(lái)源:明輝站整理相關(guān)軟件相關(guān)文章人氣:
[摘要]寫法1:update sas_order_supply_month_pay set RECEIVE_TIME=REPLACE(RECEIVE_TIME,DATE_FORMAT(RECEIVE_TIM...
寫法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';
說(shuō)明: sas_order_supply_month_pay表的RECEIVE_TIME字段格式為"2017-06-16 12:13:16",sas_task_supply_month_pay_period表的PERIOD_END字段格式為"2017-07-12",
執(zhí)行后RECEIVE_TIME修改為"2017-07-12 12:13:16"。
錯(cuò)誤寫法: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';
錯(cuò)誤寫法報(bào)錯(cuò):[Err] 1093 - You can't specify target table 'sas_order_supply_month_pay' for update in FROM clause
錯(cuò)誤分析:
錯(cuò)誤語(yǔ)句:(select DATE_FORMAT(RECEIVE_TIME,'%H:%i:%S') from sas_order_supply_month_pay where ORDER_CODE='PO201707130115')
此語(yǔ)句單獨(dú)執(zhí)行是可以的,但是合在一起執(zhí)行報(bào)錯(cuò),猜測(cè):修改表和子查詢不能是同一個(gè)表?
以上就是用MYSQL替換時(shí)間字段且時(shí)分秒不變的方法的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注php中文網(wǎng)其它相關(guān)文章!
學(xué)習(xí)教程快速掌握從入門到精通的SQL知識(shí)。