我如何仅从JPQL中的日期时间字段按日期分组 [英] How do i group by date only from date time field in JPQL
本文介绍了我如何仅从JPQL中的日期时间字段按日期分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对于mysql,我编写了一个类似
For mysql I wrote a query like
SELECT * FROM mytable GROUP BY DATE(dateTimeField)
但我不能在JPQL中使用 DATE()
函数。
任何人都知道如何解决这个问题?
But i can't use the DATE()
function in JPQL.
Anyone have an idea how to resolve this problem?
推荐答案
对于Hibernate:
For Hibernate:
建议1:
使用 cast(dateTimeField作为日期)
。请参阅此处。
建议2:
您可以尝试连接年
,月
和年
HQL表达式。
You can try to concatenate year
, month
and year
HQL expressions.
看一下< A HREF = http://kickjava.com/src/org/hibernate/test/hql/ASTParserLoadingTest.java.htm 相对= nofollow noreferrer>此测试用例。
str(year(current_date))||'-'||str(month(current_date))||'-'||str(day(current_date))
但是花点时间看看生成的SQL,它可能(也可能会)丑陋慢。
But take the time to see the generated SQL, it may (and probably will be) ugly and slow.
这篇关于我如何仅从JPQL中的日期时间字段按日期分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文