问题
I have a table in which the following query works fine:
select *
from session_actions
where action_type IN ('login_failed','channel_recorded')
Now I'm looking forward to some thing like the following:
select *
from session_actions
where action_type IN ('login_failed,channel_recorded')
As you see I want to give the IN
operator one single comma separated parameter, but it is not possible
How can I convert this comma separated string into a list of parameters which is acceptable to IN
operator?
回答1:
You might be looking for FIND_IN_SET() function.
select *
from session_actions
where find_in_set(`action_type`,'login_failed,channel_recorded');
SAMPLE FIDDLE
回答2:
I tried FIND_IN_SET
but it was super slow. I rather use haystack REGEXP CONCAT('[[:<:]]', needle, '[[:>:]]')
since then.
来源:https://stackoverflow.com/questions/4171832/comma-separated-argument-for-in-operator-mysql