判断给定时间是否在区间内,由于结束时间可能为空,若为空表示长期;希望在 end_date 可以延长180天作为最终的 end_date
-- ok
AND ((ic.price_end_date is null and ic.price_start_date <= '2022-01-22') or (ic.price_end_date is not null and '2022-01-22' BETWEEN ic.price_start_date and ic.price_end_date))
-- ok
AND ((ct.end_date is null and ct.begin_date < '2022-01-22') or (ct.end_date is not null and '2022-01-22' BETWEEN ct.begin_date and ct.end_date+INTERVAL 180 DAY ))
但是遇到的问题时这样的
时间 '2022-01-22' 经过前端传递到Java后端,后端MyBatis调用数据库,结果是查不出数据的
private LocalDate localDate;
private Date date;
postman

参数打印
![]()
debug

这个时间无法在sql查询起作用?
探讨在MySQL中判断给定日期是否在指定区间内的复杂性,特别是在结束日期可能为空或需要向前端传递特定日期格式时。文章深入分析了SQL查询语句的正确构造方法,以及在Java后端使用MyBatis调用数据库时遇到的具体问题。
423

被折叠的 条评论
为什么被折叠?



