I have a table with a timestamp field of type datetime. I need to aggregate data between a specific start and end time into groups x, representing time intervals of equal length, where x is provided as a function parameter.
What would be the best way to do this with Hibernate?
EDIT: some explanation
Mysql table:
data_ts: datetime pk value1 : int value2 : bigint ...
Entity Class:
Calendar dataTs; Integer value1; BigDecimal value2; ...
I am looking for an HQL query that does something like
select max(c.value1), avg(c.value2) from MyClass c where c.dataTs between :start and :end group by <interval>
where the entire time period is grouped into x time intervals with the same size.
Example:
Start : 2008-10-01 00:00:00 End : 2008-10-03 00:00:00 (2 days) Groups: 32
must be grouped at an interval of 1.5 hours (48 hours / 32):
2008-10-01 00:00:00 - 2008-10-01 01:29:59 2008-10-01 01:30:00 - 2008-10-01 02:59:59 2008-10-01 02:00:00 - 2008-10-01 04:29:59 ...
java mysql group-by hibernate
Wolf
source share