这个SQL语句有几个问题:

  1. SQL语句中的<where>标签没有闭合,应该在</where>后面加上一个闭合标签</select>
  2. 在条件判断语句的<if>标签中,使用了不等于null的条件判断,但是在判断条件后面没有加上一个空格,应该修改为!= null
  3. 在条件判断语句的<if>标签中,使用了字符串类型的变量,但是没有加上单引号,应该修改为'#{variable}'
  4. 在条件判断语句的<if>标签中,对于时间类型的变量,判断条件为等于=,但是对于时间类型的变量,应该使用大于等于>=或者小于等于<=的判断条件。
  5. SQL语句中的t1.isDeleted=0应该放在<where>标签之外的地方,作为整个SQL语句的限制条件。

修正后的SQL语句如下:

<select>
    select t1.*,t2.apsDeviceName,t2.wiotDeviceName,t2.processNo,t2.processName from APS_DEVICE_WORK_TIME t1,APS_PROCESS_CONFIG t2 where t1.processId =t2.id and t1.isDeleted=0
    <where>
        <if test="wiotCode != null"> and wiotCode = #{wiotCode}</if>
        <if test="processNo != null"> and processNo = #{processNo}</if>
        <if test="apsDeviceName != null"> and apsDeviceName = #{apsDeviceName}</if>
        <if test="processName != null"> and processName = #{processName}</if>
        <if test="workStartTime != null and workStartTime != ''"> and workStartTime &gt;= #{workStartTime}</if>
        <if test="workEndTime != null and workEndTime != ''"> and workEndTime &lt;= #{workEndTime}</if>
        <if test="workPeriod != null and workPeriod != ''"> and workPeriod = #{workPeriod}</if>
        <if test="processId != null"> and processId = #{processId}</if>
        <if test="createUser != null and createUser != ''"> and createUser = #{createUser}</if>
        <if test="createTime != null"> and createTime = #{createTime}</if>
        <if test="lastEditUser != null and lastEditUser != ''"> and lastEditUser = #{lastEditUser}</if>
        <if test="lastTime != null"> and lastTime = #{lastTime}</if>
    </where>
</select>
``
select t1t2apsDeviceNamet2wiotDeviceNamet2processNot2processName from APS_DEVICE_WORK_TIME t1APS_PROCESS_CONFIG t2 where t1processId =t2id and t1isDeleted=0 where if test=wiotCode !=

原文地址: https://www.cveoy.top/t/topic/hLce 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录