我想通过测试condition_1将condition_2添加到mysql where子句中。condition_1是type = 'group:1'
,condition_2是username = 'rahim'
。所以,如果满足type = 'group:1'
,那么我将在where子句中添加username = 'rahim'
。如果不满意,我不想在where条款中添加这一点。我试过username = 'rahim' CASE WHEN type = 'group:1'
。但是,它输出错误:
[Err]1064:在'CASE WHEN类型附近使用正确的语法="group:1"AND type='group:1">
SELECT
a.user_id,
b.username,
a.message,
a.type
FROM
livechat_message a
LEFT JOIN livechat_user b ON a.user_id = b.user_id
WHERE
username = 'rahim' CASE
WHEN type = 'group:1'
AND type = 'group:1'
提前谢谢。
您似乎想要:
WHERE NOT (type = 'group:1' AND username <> 'rahim')