在這裏,我想更新item_quatity是否存在其他插入行IF NOT EXISTS INSERT,UPDATE ELSE - 不工作?
+----+--------+-----------+---------------+
| id |user_id | item_id | item_quantity |
+----+--------+-----------+----------------+
| 1 | 16 | 4 | 1 |
| 2 | 5 | 6 | 2 |
+----+--------+-----------+---------------+
INSERT INTO user_items
SET user_id = 16 ,item_id = 4 , item_quantity = 1
ON DUPLICATE KEY
UPDATE item_quantity = item_quantity + '1' ;
OR
INSERT INTO user_items
(user_id,item_id,item_quantity) VALUES ('16','4','1')
ON DUPLICATE KEY
UPDATE item_quantity= item_quantity + '1' ;
這個查詢總是插入行,更新不工作???
即是關鍵獨特之處? – CaptainCarl 2013-03-25 09:37:47
你的表格模式好嗎? – hjpotter92 2013-03-25 09:38:22