进行中一共有以下几种情况:
1.开始时间为空,结束时间为空, 此结果数据将永远为进行中的数据
2.开始时间为空,结束时间不为空,则当前时间在结束时间之前,为进行中的数据
3.开始时间不为空,结束时间为空,则当前时间在开始时间之后,为进行中的数据
4.开始时间不为空,结束时间不为空,则当前时间在开始与结束时间段之内的数据为进行中数据
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>