Search code examples
jpql

JPQL Query average per X minutes


I'm trying to build a jpql query that gives me the average value in an interval of X minutes when given a start date and a end date.

Is there a way of doing this in the jpql or do I have to calculate this in Java? I don't want to write a native sql query.

This is the seudo-query to understand what I'm trying to accomplish.

'timestmamp_x', avg(d.value) FROM Data d WHERE d.startDate > :startDate AND d.endDate < :startDate 'SOMETHING to group per x minutes';

Solution

  • No, there is no way to have such a grouping JPQL, because it does not have supporting construct. There is not any way to extract minutes from date. Additionally you cannot do any kind of arithmetic calculations with dates and date functions are limited to CURRENT_DATE, CURRENT_TIMESTAMP and CURRENT_TIME.