3
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 如果我们有其他内容,请插入。有任何想法吗?

4

2 回答 2

6
  • 您需要在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;

来源

于 2012-11-12T00:52:05.530 回答
0

查找REPLACE INTO而不是INSERT INTO.

于 2012-11-12T00:50:54.937 回答