数据如图,检索字段为 knowledge_points

-- 直接上代码,用mysql正则函数 REGEXP
SELECT * FROM `question`
where concat(',', knowledge_points, ',') REGEXP ',(41|2|5),'
检索结果如下图

此处附带上多条件检索的mybatis写法

<if test="query.knowledgePointIds != null and query.knowledgePointIds.size() > 0 ">
and concat(',', q.knowledge_points, ',') REGEXP
<foreach collection="query.knowledgePointIds" item="item" index="index" open="',('" close="'),'" separator="'|'">
#{item, jdbcType=VARCHAR}
</foreach>
</if>
本文介绍了如何在MySQL中使用正则表达式进行数据检索,特别是针对`knowledge_points`字段。示例展示了如何通过`REGEXP`函数匹配多个指定条件,并给出了在MyBatis中实现多条件检索的代码片段,适用于数据筛选和查询优化。
837

被折叠的 条评论
为什么被折叠?



