2016-06-14 37 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)