开发者

Get distinct months from database using HQL

开发者 https://www.devze.com 2023-01-15 16:13 出处:网络
I have a java.util.Date field in an @Entity and would like to get the distinct months from that column.

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 开发者_StackOverflow社区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?


What about :

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号