代码之家  ›  专栏  ›  技术社区  ›  Jay

在JPA查询中使用groupby和having

  •  3
  • Jay  · 技术社区  · 15 年前

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

    select * from person where email in
    (select email from person group by email having count(email)>1)
    
    2 回复  |  直到 15 年前
        1
  •  8
  •   Jay    15 年前

    终于找到了解决办法:

    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
  •  3
  •   Cacovsky    13 年前

    this link ,这里解释了JPA SELECT查询的一般结构:

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