MySQL:使用“REGEXP"而不是“FIND_IN_SET" [英] MySQL: Usage of 'REGEXP' instead of 'FIND_IN_SET'
问题描述
我在使用 MySQL 的 FIND_IN_SET 函数用于在集合中搜索数组.因此考虑使用 REGEXP一>.但是谁能帮我构建它.
I am having limitation in using MySQL's FIND_IN_SET function for searching array in set. Hence thinking of using of REGEXP. However can anyone help me constructing it.
例如我的要求
SELECT * FROM table AS t WHERE FIND_IN_SET('1,2,3', t.list);
因此想到使用REGEXP函数在集合内搜索数组.
Hence thinking of using REGEXP function to search array within set.
SELECT * FROM table AS t WHERE t.list REGEXP '1,2,3';
谁能帮我构建这个 REGEXP.
Can anyone help me building this REGEXP.
推荐答案
您可以拆分搜索字符串并继续使用 FIND_IN_SET()
You can split your search string and continue to use FIND_IN_SET()
SELECT *
FROM `table` AS t
WHERE FIND_IN_SET('1', t.list)
AND FIND_IN_SET('2', t.list)
AND FIND_IN_SET('3', t.list)
通过引入多对多表更好地规范您的数据.
Better yet normalize your data by introducing a many-to-many table.
这篇关于MySQL:使用“REGEXP"而不是“FIND_IN_SET"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!