我已经使用以下查询来更新我在 mysql 中的用户表
update users set user_likes =
(CASE WHEN like_by_users NOT LIKE '%user_name%'
AND dislikes_by_users NOT LIKE '%user_name%'
THEN (user_likes +1) ELSE user_likes END)
WHERE post_id = '2221'
这对我来说很好,但我也想像这样更新 likes_by_users
likes_by_users = CONCAT(likes_by_users,' ','user_name')
我试过这样做
update users set user_likes =
(CASE WHEN like_by_users NOT LIKE '%user_name%'
AND dislikes_by_users NOT LIKE '%user_name%'
THEN (user_likes +1), likes_by_users = CONCAT(likes_by_users,' ','user_name')
ELSE user_likes END)
WHERE post_id = '2221'
但它根本不起作用。我不想再次检查条件,但如果上述条件为真,那么它不仅应该更新 (user_likes) 和 (likes_by_users) 两列 (user_likes),如果条件为假,那么它不应该更新任何列。