date_trunc函数在JPQL查询中的使用

huangapple go评论88阅读模式
英文:

date_trunc function in jpql query

问题

我真的被JPQL中的date_trunc函数卡住了。

我的查询是:

@Query("SELECT c.name AS name, SUM(c.salary) AS salary FROM SalaryTable AS c GROUP BY c.name, date_trunc('year', c.savedtimestamp)")

我得到了异常:

date_trunc('year' c.savedtimestamp)之间没有逗号分隔。
[197, 203] 标识变量'year'不符合Java标识符的规则。

你能帮我解决这个问题吗?

问候,
Stephan

英文:

I am really stuck with date_trunc funtion in JPQL.

My query is:

@Query("SELECT c.name AS name, SUM(c.salary) AS salary FROM SalaryTable AS c GROUP BY c.name, date_trunc('year' c.savedtimestamp)") 

I get the exception:

has 'date_trunc' and '('year' c.savedtimestamp)' that are not separated by a comma.\n[197, 203] The identification variable ''year'' is not following the rules for a Java identifier.","\tat org.eclipse.persistence.internal.jpa.jpql.HermesParser.buildException(HermesParser.java:157)","\tat org.eclipse.persistence.internal.jpa.jpql.HermesParser.validate(HermesParser.java:336)","\tat org.eclipse.persistence.internal.jpa.jpql.HermesParser.populateQueryImp(HermesParser.java:280)","\tat

Can you help me in this regard ?

Regards,
Stephan

答案1

得分: 1

date_trunc('year', c.savedtimestamp)

注意错误消息中的逗号```

has 'date_trunc' 和 '(year' c.savedtimestamp)`` 没有用逗号分隔。

英文:

Should be:

date_trunc('year', c.savedtimestamp)

Note the ',' per the error message"

has 'date_trunc' and '('year' c.savedtimestamp)' that are not separated by a comma

huangapple
  • 本文由 发表于 2020年8月12日 00:48:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/63362765.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定