between and和两个and写法的区别
between and写法:
and create_date between to_date('2019-01-01','yyyy-MM-dd') and to_date('2020-01-01','yyyy-MM-dd')
两个and写法:
and create_date >= to_date('2019-01-01','yyyy-MM-dd')
and create_date <= to_date('2020-01-01','yyyy-MM-dd')
区间查询范围越大条数反而不是越大
测试中发现一个问题,按道理说,区间的范围越大,条数应该越多。但实测条数有时多有时少。一开始以为是2个and有问题,后来发现是条件写错了。
右区间入参写错了,应该是createDateEnd,错写为createDateBegin:
<if test="createDateBegin != null">
and CREATE_DATE <![CDATA[ >= ]]> #{createDateBegin,jdbcType=TIMESTAMP}
</if>
<if test="createDateEnd != null">
<!-- 这里应该是createDateEnd -->
and CREATE_DATE <![CDATA[ <= ]]> #{createDateBegin,jdbcType=TIMESTAMP}
</if>