我需要从一个表中获取一些记录,该表的列birthDate
是Date
(没有时间)。我只需要通过比较年份和月份来过滤记录。例如,我想要所有出生于 1990 年 3 月的用户。那一天并不重要。
你如何处理它?
您可以使用from Entity where to_char(birthDate,'YYYY/MM') = '1990/03'
这将适用于 HQL
你可以试试这个
select * from table where month(birthdate)=03 and year(birthdate)=1990
这是一个适合我的 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