I've been looking in the web for examples on the aggregates like count but 开发者_开发技巧it seems all of them are using the aggregate alone.
SELECT field, count(*) FROM table GROUP BY field Should have something like: field.value1, x1 field.value2, x2 ....
I'm looking for a pure JPA answer for this one. If not I guess I can then do further queries just for the count part but that seems unefficient.
Any ideas?
I'm not sure I understood the question correctly but doesn't the following JPQL query do what you want:
SELECT p.name, count(p) from Product p group by p.name
You can retrieve the data like this:
List datos=(List)query.getResultList();
where Object[0] is the first field, Object[1] the second and so on.
精彩评论