Average date difference in QueryDSL
I have an object with a Date object representing the last activity. I would like to query the average downtime. So in SQL something like:
SELECT AVG(NOW() - idle_date) FROM mytable WHERE ....
I tried to calculate the difference like this:
query.singleResult(
Expressions.dateOperation(
Long.class,
Ops.DateTimeOps.DIFF_SECONDS,
DateExpression.currentDate(),
myTable.idleDate
)
);
But that doesn't allow me to do the average over the result, just min and max.
How can I express this average by date / time difference (in seconds)?
+3
source to share