6

我需要从一个表中获取一些记录,该表的列birthDateDate(没有时间)。我只需要通过比较年份和月份来过滤记录。例如,我想要所有出生于 1990 年 3 月的用户。那一天并不重要。

你如何处理它?

4

3 回答 3

9

您可以使用from Entity where to_char(birthDate,'YYYY/MM') = '1990/03' 这将适用于 HQL

于 2012-10-19T12:20:50.713 回答
7

你可以试试这个

 select * from table where month(birthdate)=03 and year(birthdate)=1990
于 2012-10-19T12:00:57.487 回答
1

这是一个适合我的 HQL 查询

from Person as p where year(p.birthDate)=year(:bDate) and month(p.birthDate)=month(:bDate)"

bDate的类型是Date,可以传Integer

from Person as p where year(p.birthDate)=:bYear and month(p.birthDate)=:bMonth
于 2020-04-20T16:06:04.097 回答