<select id="countAssetTab" resultType="Integer" parameterType="HashMap">
SELECT COUNT(1) FROM TTRD_ASSET_MANAGE_PLAN_EXTEND
<where>
<if test="i_code != null and i_code !=''">
AND (I_CODE = #{i_code}
OR I_CODE = CONCAT(#{i_code},'(temp)'))
</if>
<if test="a_type != null and a_type !=''">
AND A_TYPE = #{a_type}
</if>
AND ZMZC_FLAG = 1
</where>
</select>
如上,是我在公司项目中写的代码,我遇到的问题是,在
AND (I_CODE = #{i_code}
OR I_CODE = CONCAT(#{i_code},'(temp)'))
代码部分我第一次没有应用括号的情况下,查找出来的数据是不正确的,因为在sql语句中的执行顺序是not>and>or的,
因此在or的部分没有使用括号的情况下,将当前的语句变成了
AND (I_CODE = #{i_code})
OR (I_CODE = CONCAT(#{i_code},'(temp)')
AND A_TYPE = #{a_type}
AND ZMZC_FLAG = 1)
所以导致一直查找到的数据不正确。