JPQL @Query causing "unexpected token: ("

Viewed 7111

I have following method defined:

@Query("SELECT AVG(total) FROM (SELECT COUNT(t.name) total FROM DataTable t GROUP BY DATE(actiontime)) result")
Long countAvg();

However it causes this error:

Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected     token: ( near line 1, column 24 [SELECT AVG(total) FROM (SELECT     COUNT(t.name) total FROM backend.DataTable t GROUP BY     DATE(actiontime)) result]

But following SQL works fine:

SELECT AVG(total) FROM (SELECT COUNT(NAME) total FROM DATA_TABLE GROUP BY DATE(actiontime)) result 

If i understand correctly, JPQL has problems with subquery. How should i create this kind of query then?

1 Answers
Related