gpt4 book ai didi

java - 基于 Hibernate 中的某些条件的两个日期列中的日期

转载 作者:行者123 更新时间:2023-12-01 14:39:14 26 4
gpt4 key购买 nike

我有一个表,其中有两个时间戳列,代表 effectiveexpiration日期,我需要获取当前时间戳落在这两个日期列中的那些行。

这可以通过在 SQL 查询中添加条件来完成,如下所示
effectiveDate <= current_timestamp and current_timestamp < expirationDate .

问题是如果 expirationDate 则满足上述条件不为空。如果为 null,则仅
effectiveDate <= current_timestamp将被检查。

我猜这是一种动态 SQL。我在项目中使用Hibernate。我可以使用 critera API 或 HQL 或 SQL 任何东西。

请告诉我如何做到这一点。

最佳答案

您的第一个版本并不完全是 SQL。但你想要的是这样的:

where effectiveDate <= current_timestamp and
(expirationDate is NULL or current_timestamp < expirationDate)

关于java - 基于 Hibernate 中的某些条件的两个日期列中的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16154021/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com