mysql判断当前时间是否在开始与结束时间之间且开始与结束时间允许为空 |
需求:查询进行中的活动数据进行中一共有以下几种情况: 下面sql则查询的是满足以上四种需求的结果集,达标题需求SELECT * FROM 表名 WHERE 1=1 and(start_time is null or start_time<now()) and(end_time is null or end_time>now()) mybatis写法,开始时间与结束时间传入参数允许为空
<if test="record.startDate != null and record.startDate != '' or record.endDate != null and record.endDate != '' ">
AND id in
(select id from rht_product_price where 1=1
<if test="record.startDate != null and record.startDate != ''">
and start_date <= #{record.startDate,jdbcType=VARCHAR}
</if>
<if test="record.endDate!= null and record.endDate != ''">
and end_date >= #{record.endDate,jdbcType=VARCHAR}
</if>
)
</if>
到此这篇关于mysql判断当前时间是否在开始与结束时间之间且开始与结束时间允许为空的文章就介绍到这了,更多相关mysql判断当前时间是否在开始与结束时间之间内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家! |