我在DB2中使用hibernate并遇到以下问题。表/实体Customer
包含字段first_name
,last_name
,birthday
(java.util.Date
)。我需要写一个查询,它将检索所有在接下来的四天有生日的客户。问题是,对于一些客户来说,出生年份是未知的,因此在数据库中设置为9999,因此我不能只对where子句进行简单的检查(因为9999年)。
答案 0 :(得分: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)