如何在具有两个相同日期的查询之间使用 EJBQL?
我有一个 JPA 命名查询,它需要两个日期,以便返回两个日期之间具有日期列条目的记录。
如果我为开始日期和结束日期输入相同的日期,即使有该日期的记录,它也不会返回任何行。
有没有办法使查询工作,或者当两个日期相同时我应该运行另一个查询吗?
这是查询:
select o from CustomerOrder o
where o.orderDate between :date_from and :date_to
order by o.orderDate desc
I have a JPA named query that takes two dates in order to return records with a date column entry between the two dates.
If I enter the same date for both the start and end dates it returns no rows, even though there are records for that date.
Is there way to make the query work or shall I just run another query when the two dates are the same?
Here's the query:
select o from CustomerOrder o
where o.orderDate between :date_from and :date_to
order by o.orderDate desc
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我倾向于按照以下方式运行所有查询:
我很少使用
Between
- 我使用的 DBMS 具有相同的性能,无论使用哪种方法。我的建议是做一些计时,看看使用
where ... and
而不是where ... Between
是否不会导致性能下降,如果没有,则进行切换。一些 DBMS 实际上排除了“端点”(第一个和/或最后一个),这可能就是您所看到的。两个子句的 SQL 语句不应该有这个问题。
I tend to run all my queries as:
I rarely use
between
- the DBMS I use has the same perormance irrespective of which of those methods is used.My advice would be to do some timings to see if there's no performance degradation to using
where ... and
instead ofwhere ... between
and then switch if not.Some DBMS' actually exclude the "endpoints" (first and/or last) which is probably what you're seeing. The two-clause SQL statement should not have that problem.