Using group by and having in a JPA query

徘徊边缘 提交于 2019-12-14 03:48:58

问题


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

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

回答1:


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



回答2:


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

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


来源:https://stackoverflow.com/questions/3439910/using-group-by-and-having-in-a-jpa-query

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!