HQL select 按时间单位求和和时间组 (hour/day/month) 和

HQL select sum and time group by time unit (hour/day/month) and

我有一个 table 这样的:

COLUMN               TYPE
------------------------------
ID                   INTEGER
VALUE                INTEGER
TIME                 TIMESTAMP

我如何使用 HQL 编写查询,选择按时间单位分组的值列的总和(f.e。按天分组)并选择此时间单位作为第二列。

我试过了,结果是这样的: 但是 HQL 中没有 parsedatetime 函数所以我现在不知道如何才能获得正确的查询。

select sum(value),
parsedatetime(day(time) || '.' || month(time) || '.' || year(time) || ' ' || hour(time) ||':00:00', 'dd.MM.yy hh:mm:ss')
as xtime 
from Table 
group by time

我希望此查询 return 具有 2 个字段的对象:int 和 java.sql.Date。

您正在按整个日期时间值进行分组,这就是您没有预期结果的原因,您必须按您想要的日期时间片段对其进行分组,尝试如下操作:

select sum(value),
day(time) as xtime 
from Table 
group by day(time)