有我在我的mysql查詢中犯了錯誤。誰能幫我嗎??如何在WHERE子句中的mysql查詢中得到if語句?
select * from user_errors where user_id = '2'
IF(type = 'custom_type') second_user_id != '2' ELSE second_user_id = '2'
END IF
有我在我的mysql查詢中犯了錯誤。誰能幫我嗎??如何在WHERE子句中的mysql查詢中得到if語句?
select * from user_errors where user_id = '2'
IF(type = 'custom_type') second_user_id != '2' ELSE second_user_id = '2'
END IF
沒有必要使用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
使用這樣的(你不如果其他條件不需要使用)
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'))
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)
發佈錯誤消息 –