0
INSERT INTO min_product (shopid, productid , outward)
SELECT shopid, productid , outward
FROM main_product
WHERE shopid= '51'
ON DUPLICATE KEY UPDATE outward = (SELECT sum(outward)
FROM main_product WHERE shopid= '51')
main_product表上的重複密鑰更新犯規更新,而插入一行
productid outward shopid
333 2 44//present
343 4 44//present
353 5 44//present
363 1 44//present
373 2 44//not present
min_product表
productid outward shopid
333 1 44
343 1 44
353 1 44
363 1 44
的問題是,它不上重複的行更新,而新行插入?是什麼在查詢ON DUPLICATE KEY UPDATE
您可能沒有唯一鍵定義 –
@juergend唯一關鍵的是'productid' – Aryan
@JohnWoo我需要根據檢查'productid' – Aryan