时间:2021-07-01 10:21:17 帮助过:28人阅读
3,尝试把where放在每一个select语句中,不需要汇聚成一个表了,即少了别名:
select id,name,person_id from a where name like "%a%" and person_id like "%1%"
union all select id,name,person_id from b where name like "%a%" and person_id like "%1%", 卧槽,出乎意料地快!解决了问题。
4,mybatis配置文件如下:
模糊查询的总数:
<select id="getFaceDataCount" resultType="int"> select sum(c) from (<foreach collection="companyCodeList" item="item" index="index" separator="union">select count(1) as c from ${item} <where> <if test="faceData.personId != null and faceData.personId != ‘‘"> and person_id like ‘%${faceData.personId}%‘ </if> <if test="faceData.name != null and faceData.name != ‘‘"> and name like ‘%${faceData.name}%‘ </if> </where> </foreach>) as faceCount </select>
模糊查询的详细:
<select id="selectAllFaceData" resultMap="BaseResultMap"> <foreach collection="companyCodeList" item="item" index="index" separator="union">(select <include refid="Base_Column_List" /> from ${item} <where> <if test="faceData.personId != null and faceData.personId != ‘‘"> person_id like ‘%${faceData.personId}%‘ </if> <if test="faceData.name != null and faceData.name != ‘‘"> and name like ‘%${faceData.name}%‘ </if> </where> )</foreach> limit #{start},#{limit} </select>
mysql模糊查询的优化方法--亲自实践
标签:mysql模糊查询的优化方法--亲自实践