【问题标题】:Multiple columns in group by clause in hibernatehibernate中group by子句中的多个列
【发布时间】:2012-05-17 17:36:44
【问题描述】:

如何在休眠中按查询分组(例如 Select column1,column2,min(value) from Foo_Bar where value> 100 group by (Column1,Column2) )?我希望有多列分组部分。

【问题讨论】:

  • group by 只能在其他列是聚合函数(sum、count、avg等)的结果时使用,如SQL中:select column1,column2,sum(value) from FooBar group by column1, column2
  • 是的,即使我试图做同样的事情,只是之前发布了错误的查询。由于我已经编辑了这个问题,您能帮忙解决这个修改后的查询吗?

标签: hibernate group-by


【解决方案1】:
select f.column1, f.column2, min(f.value)
from FooBar f
where f.value > 100
group by f.column1, f.column2

【讨论】:

  • 这是 sql 查询,我想要它的 hibernate 等价物。
  • 这是非常好的 JPQL 查询,并且与 Hibernate 配合得很好。如果属性名称与您的实体不匹配,只需更改它们。 (+1)。
猜你喜欢
  • 2011-04-24
  • 2016-08-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-09-29
  • 2018-03-23
  • 1970-01-01
相关资源
最近更新 更多