1.sql语句:
SELECT 字段 from 表名 where 时间字段 BETWEEN ‘2019-05-22’ AND ‘2019-06-21’
注:此种方法查到的是5-22到6-20之间数据,不包括6-21当天的数据;
2.在mybatis中mapper文件定义查询:
<select id="selectByTime" resultMap="" parameterType="" >
select 字段 from 表名
<where>
<if test="endDate !=null and endDate != '' ">
<![CDATA[ SUBSTR(create_date,1,10) <= #{endDate} ]]>
</if>
<if test="beginDate != null and beginDate != '' ">
<![CDATA[ and SUBSTR(create_date,1,10) >= #{beginDate} ]]>
</if>
</where>
注:与1不同的是查询到的数据包括结束日期当天的数据(即包括6-21);