2010-11-13 34 views
3

我在下面的查詢工作正常的表:逗號分隔的論據IN操作符,MySQL的

select * 
from session_actions 
where action_type IN ('login_failed','channel_recorded') 

現在我很期待一些東西像下面這樣:

select * 
from session_actions 
where action_type IN ('login_failed,channel_recorded') 

正如你看到我想給IN運營商一個逗號分隔參數,但它不可能

如何將此逗號分隔的字符串轉換爲參數列表這是IN運營商可以接受的嗎?

回答

2

您可能正在尋找FIND_IN_SET()功能。

select * 
from session_actions 
where find_in_set(`action_type`,'login_failed,channel_recorded'); 

SAMPLE FIDDLE

0

我試圖FIND_IN_SET但它是超慢。從那以後我寧願使用haystack REGEXP CONCAT('[[:<:]]', needle, '[[:>:]]')