2

我在 DB2 中使用休眠并遇到以下问题。表/实体Customer具有字段first_name, last_name, birthday( java.util.Date)。我需要编写一个查询来检索所有在接下来的四天内过生日的客户。问题是,对于某些客户来说,出生年份是未知的,因此在数据库中将其设置为 9999,因此我不能只在 where 子句中进行简单的检查(因为是 9999 年)。

4

1 回答 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)
于 2012-08-31T17:36:37.410 回答