Reputation: 93
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;
I am trying to update GameScoreTotal If we have something there otherwise insert. Any ideas?
Upvotes: 3
Views: 2671
Reputation: 263723
GameName
name, (a unique or primary key should do)WHERE
clause from the insert statementquery,
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
Upvotes: 7