本文介绍了MySQL:使用“REGEXP"而不是“FIND_IN_SET"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在使用 MySQL 的 FIND_IN_SET 函数用于在集合中搜索数组.因此考虑使用 REGEXP.但是谁能帮我构建它.
SELECT * FROM table AS t WHERE FIND_IN_SET('1,2,3', t.list);
Hence thinking of using REGEXP function to search array within set.
SELECT * FROM table AS t WHERE t.list REGEXP '1,2,3';
Can anyone help me building this REGEXP.
推荐答案
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"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!