Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/67.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 如何确保sql中的两个字符串相交?_Mysql_Sql - Fatal编程技术网

Mysql 如何确保sql中的两个字符串相交?

Mysql 如何确保sql中的两个字符串相交?,mysql,sql,Mysql,Sql,用“,”分隔的两个字符串如下: a:‘1,2,3,4,5’ b:'6,2,1,3,9' 我想确定这些字符串是否有交叉点 有什么功能可以在mysql中处理吗? 谢谢 我必须强调,只要问这个问题就可以清楚地表明您的数据结构是错误的。你应该为每一对都准备一张桌子。它将有如下行: a 1 a 2 . . . b 6 b 2 etc. 使用标准SQL很容易解决这个问题 也就是说,如果您出于某种原因被迫这样做,MySQL有一些功能可以提供帮助。您可以执行以下操作: where fi

用“,”分隔的两个字符串如下:

a:‘1,2,3,4,5’
b:'6,2,1,3,9'

我想确定这些字符串是否有交叉点

有什么功能可以在mysql中处理吗?


谢谢

我必须强调,只要问这个问题就可以清楚地表明您的数据结构是错误的。你应该为每一对都准备一张桌子。它将有如下行:

a    1
a    2
. . .
b    6
b    2
etc.
使用标准SQL很容易解决这个问题

也就是说,如果您出于某种原因被迫这样做,MySQL有一些功能可以提供帮助。您可以执行以下操作:

where find_in_set(substring_index(substring_index(a, ',', 1), ',', -1), a) > 0 or
      find_in_set(substring_index(substring_index(a, ',', 2), ',', -1), a) > 0 or
      find_in_set(substring_index(substring_index(a, ',', 3), ',', -1), a) > 0 or
      find_in_set(substring_index(substring_index(a, ',', 4), ',', -1), a) > 0 or
      find_in_set(substring_index(substring_index(a, ',', 5), ',', -1), a) > 0 or
      . . .

表达式
substring\u index(substring\u index(a,,,,,,,,,,,,,,,-1)
是一个MySQL表达式,返回字符串中的第n个值。

可能会对您有所帮助。不幸的是,这正是当您无法规范化数据库时遇到的问题。@dasblinkenlight yes!事实就是这样!但这些字符串将在运行时决定。mybe'1,2,3''1,2,3,4,5,6'或'7,4,2,6,7,8''0,2,4,9'