如何在具有两个相同日期的查询之间使用 EJBQL?

发布于 2024-08-17 06:02:22 字数 290 浏览 3 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ゞ记忆︶ㄣ 2024-08-24 06:02:22

我倾向于按照以下方式运行所有查询:

select fld from tbl
where date >= &start_date
  and date <= &end_date;

我很少使用 Between - 我使用的 DBMS 具有相同的性能,无论使用哪种方法。

我的建议是做一些计时,看看使用 where ... and 而不是 where ... Between 是否不会导致性能下降,如果没有,则进行切换。

一些 DBMS 实际上排除了“端点”(第一个和/或最后一个),这可能就是您所看到的。两个子句的 SQL 语句不应该有这个问题。

I tend to run all my queries as:

select fld from tbl
where date >= &start_date
  and date <= &end_date;

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 of where ... 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文