JPA 有没有办法做类似 SELECT, count(*) FROM的事情?分组依据<字段>字段>
我一直在网上寻找有关计数等聚合的示例,但似乎它们都单独使用聚合。
SELECT field, count(*) FROM table GROUP BY field Should have something like: field.value1, x1 field.value2, x2 ....
我正在寻找一个纯粹的 JPA 答案。如果不是,我想我可以对计数部分进行进一步的查询,但这似乎效率不高。
有什么想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定我是否正确理解了这个问题,但以下 JPQL 查询是否符合您的要求:
您可以像这样检索数据:
List datos=(List)query.getResultList();
其中 Object[0] 是第一个字段,Object[1] 是第二个字段,依此类推。
I'm not sure I understood the question correctly but doesn't the following JPQL query do what you want:
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.