IN运算符(MySQL)的逗号分隔参数 [英] comma separated argument for IN operator, MySQL

查看:153
本文介绍了IN运算符(MySQL)的逗号分隔参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可以在其中执行以下查询的表:

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')

如您所见,我想给IN运算符一个逗号分隔的参数,但这是不可能的

As you see I want to give the IN operator one single comma separated parameter, but it is not possible

如何将该逗号分隔的字符串转换为IN运算符可接受的参数列表?

How can I convert this comma separated string into a list of parameters which is acceptable to IN operator?

推荐答案

您可能正在寻找

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

这篇关于IN运算符(MySQL)的逗号分隔参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆