是否有可能有一个查询来检查是否满足条件,并且取决于答案 a)INSERT
或 b) UPDATE
?
(Mandar在回答中提出了更好的例子)
CASE
WHEN
IF EXISTS (SELECT action FROM database where action = 'eat' AND user = 'me')
THEN (UPDATE database set action = 'digest' where user = 'me')
WHEN
IF EXISTS (SELECT action FROM database where action = 'inhale' AND user = 'me')
THEN (UPDATE database set action = 'exhale' where user = 'me')
ELSE (INSERT INTO database (user,action) VALUES ('me','living'))
END CASE
它没有给出预期的结果。