使用 HQL 从数据库获取不同月份

发布于 2024-09-18 12:20:49 字数 333 浏览 2 评论 0原文

我在 @Entity 中有一个 java.util.Date 字段,并且希望从该列中获取不同的月份。

假设我只有三行,分别是 14/07/2010、24/11/1975 和 03/11/1975(欧洲日期格式 - 日/月/年),我想从 Hibernate 获取以下内容以进入用于过滤数据的下拉列表:(

07/2010
11/1975

或其他字段设置为零的相应日期对象 - 说实话,数据返回的方式并不是太重要,因为我可以解决这个问题)。

我猜 HQL 中的数据库不可知方法是不可能的 - 有什么建议吗?

I have a java.util.Date field in an @Entity and would like to get the distinct months from that column.

Suppose I only had three rows, with 14/07/2010, 24/11/1975 and 03/11/1975 (European date format - day/month/year), I would like to get the following back from Hibernate to go into a dropdown for filtering the data:

07/2010
11/1975

(or corresponding Date objects with the other fields set to zero - to be honest precisely how the data comes back isn't too important as I can work around that).

I'm guessing a database-agnostic approach in HQL isn't possible - any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

风苍溪 2024-09-25 12:20:49

怎么样:

select distinct month(c.birthday), year(d.birthday) from Cat c

What about :

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