【发布时间】:2012-10-10 00:51:18
【问题描述】:
我需要从具有birthDate 列的表中获取一些记录,该列是Date(没有时间)。我只需要通过比较年份和月份来过滤记录。
例如,我想要所有出生于 1990 年 3 月的用户。日期无关紧要。
你是怎么处理的?
【问题讨论】:
我需要从具有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
【讨论】: