effect_start_date 生效开始时间,effect_end_date:生效截止时间。传入日期,查出在生效范围内的数据,如果是生效开始时间或者生效截止时间空的话,则去掉相应的比较条件:
sql:
SELECT
match_flight_no
FROM
`t_share_flight`
WHERE
origin_flight_no = #{flightNo, jdbcType=VARCHAR}
AND IF ((effect_start_date is not null and effect_start_date <> ''), effect_start_date <= #{date, jdbcType=VARCHAR}, 1 = 1)
AND IF ((effect_end_date is not null and effect_end_date <> ''), effect_end_date >= #{date, jdbcType=VARCHAR}, 1 = 1)
IF()函数的使用
IF(expr1,expr2,expr3),如果expr1的值为true,则返回expr2的值,如果expr1的值为false,则返回expr3的值。