首先主键是索引insert into ys_yssf_rj(customerId,settleDate,settleMoney,settleActual, settleBalance,settleAccountState)VALUES(#customerId#,now(),#settleMoney#,#settleActual#,#settleBalance#,#settleAccountState#)ON DUPLICATE KEY UPDATEsettleDate = now(),settleMoney = #settleMoney#,settleActual = #settleActual#,settleBalance = #settleBalance#,settleAccountState = #settleAccountState#以前的做法是先根据主键去查找是否存在记录,找到就update,找不到就insert。需要写两条语句on duplicate key update 的写法,很简单的解决了上面的问题,而且只需要写一条语句。
原文地址:https://www.cnblogs.com/lqh969696/p/11387451.html
时间: 2024-10-10 07:04:17