有我在我的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)
发布错误消息 –