以下代码是我在Navicat for Mysql中编写的触发器。插入部分工作正常但是为了更新,我需要根据id更新特定的行数量。如何在update sql查询中编写where子句。
insert into closingstockt(CLS_BSID,CLS_Qty,CLS_SQty,CLS_CDate)
select BS_ID as CLS_BSID,BS_Qty as CLS_Qty,BSS_Qty as CLS_SQty,curdate()
from barstockt
where CLS_BSID=BS_ID
on duplicate key update CLS_Qty=BS_Qty,CLS_SQty=BSS_Qty
答案 0 :(得分:0)
ON DUPLICATE KEY UPDATE
将更新数据库中已存在的行。例如:
INSERT INTO table (field,field2) VALUES ('data1','data2')
ON DUPLICATE KEY UPDATE lastupdate=NOW()
编辑:我建议使用IF()