gpt4 book ai didi

MySQL 如果行存在则更新,否则插入

转载 作者:可可西里 更新时间:2023-11-01 07:56:49 25 4
gpt4 key购买 nike

INSERT INTO GameScoreTotal (
`GameName`
, `OverallScore`
, `GraphicsScore`
, `StoryScore`
, `GameplayScore`
, `TimeScore`
)
VALUES (
'HomeFront'
, '1'
, '1'
, '1'
, '1'
, '5'
)
WHERE GameName = 'HomeFront'
ON DUPLICATE KEY

UPDATE OverallScoreTotal = OverallScoreTotal + '1'
, GraphicsTotal = GraphicsTotal + '1'
, StoryTotal = StoryTotal + '1'
, GameplayTotal = GameplayTotal + '1'
, TimeTotal = TimeTotal + '1'
, RatingCount = RatingCount + 1;

我正在尝试更新 GameScoreTotal 如果我们有其他内容,请插入。有什么想法吗?

最佳答案

  • 您需要在 GameName 名称上定义键,(应该使用唯一键或主键)
  • 从插入语句中删除 WHERE 子句

查询,

INSERT INTO GameScoreTotal ( `GameName` , `OverallScore` , `GraphicsScore`
, `StoryScore` , `GameplayScore` , `TimeScore` )
VALUES ( 'HomeFront' , 1 , 1 , 1 , 1 , 5 )
ON DUPLICATE KEY
UPDATE OverallScoreTotal = OverallScoreTotal + 1
, GraphicsTotal = GraphicsTotal + 1
, StoryTotal = StoryTotal + 1
, GameplayTotal = GameplayTotal + 1
, TimeTotal = TimeTotal + 1
, RatingCount = RatingCount + 1;

来源

关于MySQL 如果行存在则更新,否则插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13337082/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com