java 在 JPA 查询中使用 group by 和 have

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3439910/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 01:52:20  来源:igfitidea点击:

Using group by and having in a JPA query

javaormjpajpql

提问by Jacob

How would you do the following using the JPA query language?

您将如何使用 JPA 查询语言执行以下操作?

select * from person where email in
(select email from person group by email having count(email)>1)

回答by Jacob

Finally found a solution:

终于找到了解决办法:

select p from Person p
where p.email in (
    select q.email
    from Person q
    group by q.email having count(q.email)>1)
order by p.email, p.id

回答by Cacovsky

From this link, there's a explanation of the general structure of a JPA SELECT Query:

这个链接,有一个 JPA SELECT 查询的一般结构的解释:

SELECT ... FROM ...
[WHERE ...]
[GROUP BY ... [HAVING ...]]
[ORDER BY ...]