本文由我司收集整编,推荐下载,如有疑问,请与我司联系可能使用一个MySQL查询?“列包含数组的任何值”
可能使用一个MySQL查询?“列包含数组的任何值”[英]Possible with one MySQL query? “column contains any of the array’s values” Basically I want to check whether a mysql text column, which contains comma-separated values, contains any of the values contained in an array. I know this can be done with a loop and multiple queries, but I was hoping for a single query. Is this possible? Thank you.
 基本上,我想检查包含逗号分隔值的mysql文本列是否包含数组中包含的任何值。我知道这可以通过一个循环和多个查询来完成,但我希望只有一个查询。这是可能的吗?谢谢你!
 str RLIKE CONCAT(‘[[: :]]’, REPLACE(‘values,in,the,array’, ‘,’, ‘[[: :]]|[[: :]]’), ‘[[: :]]’) this will make the following string:mysql 字符串转数组
 这将使以下字符串:
  ‘values,in,the,array’ like this:
 是这样的:
  [[: :]]values[[: :]]|[[: :]]in[[: :]]|[[: :]]the[[: :]]|[[: :]]array[[: :]] [[: :]] and [[: :]] are word boundaries so it will match only whole words, and | is an OR so it will match any of the words. Please see fiddle here.
 [[:]]和[[: :]]是单词的边界,因此它只匹配整个单词,而|是一个,因此它将匹配任何一个单词。请在这里看到小提琴。
  1
 SELECT COUNT(*) FROM my_table WHERE (my_column LIKE ‘%,0,%’ OR my_column LIKE ‘%,1,%’);
 从my_table中选择COUNT(*),其中(my_column如’%,0,%’或my_column 如’%,1,%’);
  or
 或

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。