2016-06-14 40 views

回答

0

没有必要使用if else,反正试试这个;)

select * from user_errors 
where user_id = '2' 
and ((type = 'custom_type' and second_user_id != '2') or second_user_id = '2') 

或者你必须使用它,试试这个;)

select * from user_errors 
where user_id = '2' 
and case when type = 'custom_type' then second_user_id != '2' else second_user_id = '2' end 
0

使用这样的(你不如果其他条件不需要使用)

select * from user_errors where user_id = '2' 
and ((type = 'custom_type' and second_user_id != '2') 
or (type != 'custom_type' and second_user_id = '2')) 
0

试试这个

select * from user_errors 
where user_id = '2' 
IF(type = 'custom_type', second_user_id != '2', second_user_id = '2') 
+0

你应该已经指出了'IF()'函数,它使用的是和''IF''THEN' END IF'语句之间的差异,其OP试图使用MySQL作为它们的支持。 – Marki555

+0

我不明白你的观点 – Qazi

0
SELECT * FROM user_errors 
WHERE user_id = '2'AND (case when type = 'custom_type' then second_user_id != '2' else second_user_id = '2' end)