在 Hibernate 中检索未来四天内过生日的所有客户

问题描述 投票:0回答:1

我将 Hibernate 与 DB2 一起使用,并遇到以下问题。表/实体

Customer
具有字段
first_name
last_name
birthday
(
java.util.Date
)。

我需要编写一个查询,它将检索在接下来的四天内过生日的所有客户。问题是,对于某些客户的出生年份是未知的,因此在数据库中将其设置为

9999
,因此,我不能只在
where
子句中进行简单的检查(因为年份
9999 
)。

java database hibernate db2 hql
1个回答
1
投票

使用简单的 hql 查询

from Customer as user where month(user.birthday) = month(current_date()+4 days) and day(user.birthday) = day(current_date()+4 days)
union all
from Customer as user where month(user.birthday) = month(current_date()+3 days) and day(user.birthday) = day(current_date()+3 days)
union all
from Customer as user where month(user.birthday) = month(current_date()+2 days) and day(user.birthday) = day(current_date()+2 days)
union all
from Customer as user where month(user.birthday) = month(current_date()+1 day) and day(user.birthday) = day(current_date()+1 day)
© www.soinside.com 2019 - 2024. All rights reserved.