我有这样的声明:
UPDATE `MyTable`
SET point = point + 1
WHERE (mySubject = 'MATHEMATICS' AND myGrade = '100') OR
(mySubject = 'PHYSICS' AND myGrade = '75') OR
(mySubject = 'PHYSICS' AND myGrade = '75')
我希望将表格更新为:
MATHEMATICS | 100 | 1
PHYSICS | 75 | 2
代替
PHYSICS | 75 | 1
出现重复的“物理”条件的原因是因为我从另一个函数中获取了这些信息。而且我想知道如果另一个函数通过我的 PHYSICS 2 次,我是否可以将 PHYSICS 点增加 2。
有没有办法在一个连接中执行此操作,而不是调用 UPDATE 3 次:
UPDATE `MyTable` SET point = point + 1 WHERE mySubject = 'MATHEMATICS' AND myGrade = '100'
UPDATE `MyTable` SET point = point + 1 WHERE mySubject = 'PHYSICS' AND myGrade = '75'
UPDATE `MyTable` SET point = point + 1 WHERE mySubject = 'PHYSICS' AND myGrade = '75'