英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论