我是mysql新手,我想在查询中使用if else语句
IF (EXISTS (SELECT user_token
FROM upvotes
WHERE user_token ="user_token" AND comment_token = "comment_token"
)
)
THEN (DELETE
FROM upvotes
WHERE user_token = 'user_token' AND comment_token = "comment_token"
)
AND
(UPDATE comments
SET upvote = upvote +1
WHERE token = "comment_token"
)
ELSE (INSERT INTO upvotes(user_token,comment_token
VALUES('user_token','comment_token'
)
AND
(UPDATE comments
SET upvote = upvote -1
WHERE token = "comment_token"
)
END IF
但是这个错误发生了 Unrecognized statement type. (near "IF" at position 0) SQL query: Copy Documentation
1条答案
按热度按时间but5z9lq1#
在普通的sql查询中不能这样做。必须在函数或存储的pricedure中执行此操作
你会撞到: