mysql根据关键词查询匹配多个字段时结果不正确
Posted cailijuan
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql根据关键词查询匹配多个字段时结果不正确相关的知识,希望对你有一定的参考价值。
一开始的写法
SELECT rrc.id, rrc.resource_name rrc.is_publish FROM res_resource_catalog AS rrc <where> <if test="keyWord != null and keyWord != ‘‘"> AND rrc.resource_name LIKE concat(concat("%",#keyWord),"%") OR rrc.resource_abstract LIKE concat(concat("%",#keyWord),"%") OR rrc.id IN (SELECT DISTINCT resource_id FROM res_info_item WHERE item_name LIKE concat(concat("%",#keyWord),"%")) </if> AND rrc.is_publish = 1 </where>
正确的写法:在<if>里面增加一对()
SELECT rrc.id, rrc.resource_name rrc.is_publish FROM res_resource_catalog AS rrc <where> <if test="keyWord != null and keyWord != ‘‘"> AND (rrc.resource_name LIKE concat(concat("%",#keyWord),"%") OR rrc.resource_abstract LIKE concat(concat("%",#keyWord),"%") OR rrc.id IN (SELECT DISTINCT resource_id FROM res_info_item WHERE item_name LIKE concat(concat("%",#keyWord),"%"))) </if> AND rrc.is_publish = 1 </where>
以上是关于mysql根据关键词查询匹配多个字段时结果不正确的主要内容,如果未能解决你的问题,请参考以下文章