Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MySQL喜欢多个值_Mysql_Sql_Sql Like - Fatal编程技术网

MySQL喜欢多个值

MySQL喜欢多个值,mysql,sql,sql-like,Mysql,Sql,Sql Like,我有一个MySQL查询 我有包含此内容的数据库字段 sports,shopping,pool,pc,games shopping,pool,pc,games sports,pub,swimming, pool, pc, games 为什么这样的查询不起作用? 我需要运动场还是酒吧,或者两者都要 SELECT * FROM table WHERE interests LIKE ('%sports%', '%pub%') a、b、c列表仅适用于中。对于类似情况,您必须使用或: 您的查询

我有一个MySQL查询

我有包含此内容的数据库字段

sports,shopping,pool,pc,games 
shopping,pool,pc,games 
sports,pub,swimming, pool, pc, games   
为什么这样的查询不起作用? 我需要运动场还是酒吧,或者两者都要

SELECT * FROM table WHERE interests LIKE ('%sports%', '%pub%')
a、b、c列表仅适用于中。对于类似情况,您必须使用或:

您的查询应该是SELECT*FROM`table`,其中在\u setinterests,sports,pub>0中查找\u

我的理解是,您将兴趣存储在表的一个字段中,这是一种误解。您肯定应该有一个兴趣表。

更快的方法:

这是:

在此处找到此解决方案:


关于REGEXP的更多信息:

如果在AND参数之后使用此函数,请不要忘记使用括号

像这样:

WHERE id=123 and(interests LIKE '%sports%' OR interests LIKE '%pub%')

为什么不试试REGEXP呢。试着这样做:

SELECT * FROM table WHERE interests REGEXP 'sports|pub'

正如@Alexis Dufrenoy所提议的,问题可能是:

SELECT * FROM `table` WHERE find_in_set('sports', interests)>0 OR find_in_set('pub', interests)>0
有关详细信息,请参见。

,您也可以使用REGEXP的同义词RLIKE

例如:

挑选* 从表\u名称 其中COLNAME RLIKE'REGEX1 | REGEX2 | REGEX3' 更多工作示例:

SELECT COUNT(email) as count FROM table1 t1 
JOIN (
      SELECT company_domains as emailext FROM table2 WHERE company = 'DELL'
     ) t2 
ON t1.email LIKE CONCAT('%', emailext) WHERE t1.event='PC Global Conference";

如果电子邮件扩展名等于多个公司域,或者如果您只需要匹配单词的开头,则任务是使用筛选器对事件中的参与者进行计数:

WHERE interests LIKE 'sports%' OR interests LIKE 'pub%'
您可以使用regexp插入符号匹配:

WHERE interests REGEXP '^sports|^pub'

如果您以字符串a | b | c.的形式传入未知数量的关键字,如果您想这样做,regexp是唯一的方法,是吗?您知道这是否可以通过子查询完成吗?假设我有一列需要搜索的单词,如何用子查询替换“sports | pub”?嘿,你能告诉我LIKE而不是%LIKE%的REGEXP吗,我正在尝试获取精确的字符串…此解决方案将第一个字符串从水中吹出,以从列中获取regexp值:select group_concatmyColumn separator“|”from..耶!!我想要相反的方式。所以它是从表中选择的,其中兴趣不是REGEXP‘sports | pub’>◠✌这个答案与你5年前提交的jazkat答案有何不同?@Vaidas-谢谢-问了我同样的问题…:我认为它应该是SELECT*FROM表格,其中find_in_setinterests,'sports,pub',但这种技术在大多数情况下都可能优于正则表达式。在多个(比如说5个或更多)动态可搜索查询中,这不会有好处,因此,最好使用正则表达式。@ShayanAhmad您所说的有益是什么意思?在创建查询或查询执行时间方面?是不是比REGEXP更像otpmized?请注意,RLIKE和REGEXP是同义词
SELECT COUNT(email) as count FROM table1 t1 
JOIN (
      SELECT company_domains as emailext FROM table2 WHERE company = 'DELL'
     ) t2 
ON t1.email LIKE CONCAT('%', emailext) WHERE t1.event='PC Global Conference";
WHERE interests LIKE 'sports%' OR interests LIKE 'pub%'
WHERE interests REGEXP '^sports|^pub'