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如果我们有其他东西,否则插入。有什么想法吗?
答案 0 :(得分: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;
SOURCE
答案 1 :(得分:0)
查找REPLACE INTO
而不是INSERT INTO
。