在JPA查询中使用group by和having

时间:2010-08-09 12:20:18

标签: java orm jpa jpql

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

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

2 个答案:

答案 0 :(得分:8)

终于找到了解决方案:

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

答案 1 :(得分:3)

this link开始,解释了JPA SELECT Query的一般结构:

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