Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个名为 JPA 的查询,它需要两个日期,以便返回两个日期之间带有日期列条目的记录。
如果我为开始日期和结束日期输入相同的日期,即使该日期有记录,它也不会返回任何行。
有没有办法使查询工作,或者当两个日期相同时我应该运行另一个查询?
这是查询:
select o from CustomerOrder o where o.orderDate between :date_from and :date_to order by o.orderDate desc
我倾向于将所有查询运行为:
select fld from tbl where date >= &start_date and date <= &end_date;
我很少使用between- 无论使用哪种方法,我使用的 DBMS 都具有相同的性能。
between
我的建议是做一些时间来查看使用where ... and而不是是否没有性能下降,where ... between如果没有则切换。
where ... and
where ... between
一些 DBMS' 实际上排除了“端点”(第一个和/或最后一个),这可能就是您所看到的。两句 SQL 语句不应该有这个问题。