【问题标题】:how to add one day to sql date?如何在sql日期中添加一天?
【发布时间】:2011-09-12 23:42:13
【问题描述】:

我想得到发生在contractStartdate 和contractEndDate+1day 之间的行程。但是下面的代码给了我错误。

def tripsForThisContract =  Trip.executeQuery("From Trip where contract_id = ? AND startDate between ? AND DATE_ADD('?',INTERVAL 1 DAY)",[contractId,contractStarts,contractEnds])

请帮帮我。

【问题讨论】:

  • 你能显示错误和生成的查询吗?
  • [2011-06-11 14:08:59:937] 错误 org.hibernate.hql.PARSER ### 第 1:112 行:意外令牌:1 [2011-06-11 14: 08:59:953] 错误 groovy.grails.web.errors.GrailsExceptionResolver ### 意外令牌:1 靠近第 1 行,第 112 列 [来自 com.springpeople.steer.trips.Trip where contract_id = ?和 startDate 之间? AND DATE_ADD('?',INTERVAL 1 DAY)] org.hibernate.hql.ast.QuerySyntaxException: 意外令牌: 1 靠近第 1 行,第 112 列 [来自 com.springpeople.steer.trips.Trip where contract_id = ?和 startDate 之间? AND DATE_ADD('?',INTERVAL 1 DAY)] 在 $Proxy12.createQuery(Unknown Source)

标签: mysql hibernate grails hql


【解决方案1】:

您应该处理代码中的日期。 hql不具备底层数据库的所有功能。

你的代码应该是这样的:

Trip.executeQuery(
"From Trip where contract_id = ? AND startDate between ? AND ?)"
,[contractId,contractStarts, ++contractStarts])

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-06
    • 1970-01-01
    • 2019-10-30
    • 2017-07-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多