Hibernate 使用GROUPBY的HQL查询

Hibernate 使用GROUPBY的HQL查询,hibernate,hql,Hibernate,Hql,我有以下带有字段的类结构(使用Hibernate映射): 身份证 单价 名字 颜色 如何创建一个hql查询,以获取每种颜色的花,该颜色的最低单价为(ve) 我试过这个,但不起作用 from FlowerDAO as f where f.unitPrice<= (select min(f2.unitPrice) from FlowerDAO as f2 where f2.color=f.color) group by f.color 来自FlowerDAO as f,其中f.u

我有以下带有字段的类结构(使用Hibernate映射):

  • 身份证

  • 单价

  • 名字

  • 颜色

    如何创建一个hql查询,以获取每种颜色的花,该颜色的最低单价为(ve)

我试过这个,但不起作用

from FlowerDAO as f where f.unitPrice<= (select min(f2.unitPrice) from FlowerDAO as f2 where f2.color=f.color)
group by f.color

来自FlowerDAO as f,其中f.unitPrice我怀疑问题在于将单个值与一组结果进行比较。试着换一个新的
from FlowerDAO as f 
  where f.unitPrice in 
    (select min(f2.unitPrice) from FlowerDAO as f2 where f2.color=f.color)
order by f.color