MySQL insert row on duplicate key update multiple columns

后端 未结 3 1889
情歌与酒
情歌与酒 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 18:04

    Add a computed column (sum) and include that in your PK.

    However, this does denormalize your table. You could use a surrogate key and do the calculation in your SELECT

提交回复
热议问题