MySQL insert row on duplicate key update multiple columns

后端 未结 3 1894
情歌与酒
情歌与酒 2020-12-03 17:05

I have a table (name, date, stat1, stat2, stat3), (name, date) is the PK. When I insert rows, there will be duplicate keys, and I need to sum up th

3条回答
  •  难免孤独
    2020-12-03 17:44

    INSERT INTO tb (name, date, stat1, stat2, stat3)
    VALUES (?, ?, ?, ?, ?)
    ON DUPLICATE KEY UPDATE stat1 = stat1 + VALUES(stat1), stat2 = stat2 + VALUES(stat2), stat3 = stat3 + VALUES(stat3)
    

提交回复
热议问题