mysql过滤查询结果,IF的使用

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的值。

参考:https://blog.csdn.net/yan_yzy/article/details/78210441

发布了70 篇原创文章 · 获赞 63 · 访问量 23万+

猜你喜欢

转载自blog.csdn.net/xiaoxiangzi520/article/details/100101727