Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/62.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-在CSV列中搜索CSV_Mysql_Sql_Search_Csv - Fatal编程技术网

MySQL-在CSV列中搜索CSV

MySQL-在CSV列中搜索CSV,mysql,sql,search,csv,Mysql,Sql,Search,Csv,我有一个表,其中一列包含CSV TableA: field_id | matches --------------------- 1 1,2,4,6,8,11,14,56 现在我需要获取与用户给定csv匹配的字段\u id。例如,用户字符串是1,4,11,那么它应该返回一些值,可能只是true 1.在集合中查找不起作用。因为它只接受一个元素并在SET/CSV列中搜索该元素。 2.)不能使用如concat(“,”,用户输入“,”)。因为用户输入可能不符合顺序 还有其他

我有一个表,其中一列包含CSV

TableA:

field_id  |  matches
---------------------
   1         1,2,4,6,8,11,14,56
现在我需要获取与用户给定csv匹配的
字段\u id
。例如,用户字符串是
1,4,11
,那么它应该返回一些值,可能只是
true

1.
在集合中查找不起作用。因为它只接受一个元素并在SET/CSV列中搜索该元素。
2.)不能使用
如concat(“,”,用户输入“,”)
。因为用户输入可能不符合顺序

还有其他想法吗?我想这是一种非常常见的情况


注意:我不需要搜索所有记录。我需要搜索特定的记录。因此,在上表中,我只需要搜索一条具有
字段\u id=1
的记录。i、 e.(
其中字段id=1
)。(可能不重要,但只是一个信息)

好吧,这是一个以适当的关系形式保存数据的好理由。但是,您可以尝试:

select t.*
from t
where (find_in_set($user_input, 1) = 0 or
       find_in_set(substring_index(substring_index($user_input, ',', find_in_set($user_input, 1)), ',', -1), matches) > 0) and
      (find_in_set($user_input, 2) = 0 or
       find_in_set(substring_index(substring_index($user_input, ',', find_in_set($user_input, 2)), ',', -1), matches) > 0) and
     . . .

无论用户输入集中有多少个值,都要这样做。

我认为MySQL查询没有像
Find\u in\u set
这样的直接解决方案。因此,我想我必须用多个查询或循环来处理这个问题。

这不是常见的情况,因为以逗号分隔的列表等非规范形式存储数据是非常糟糕的做法。如果可以的话,我建议您考虑将数据标准化,因为查询变得微不足道。我同意。但这是我不能改变的设计。它的巨大产品已经投入生产很长时间了。@KevinRave。我方便地省略了更痛苦的
子字符串索引部分。