0

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

  • ID

  • 单价

  • 姓名

  • 颜色

    我如何创建一个 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
4

1 回答 1

2

我怀疑问题是将单个值与一组结果进行比较。尝试将 <= 替换为“in”,这样您的查询将显示为:

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

反而?

于 2009-01-28T15:21:39.823 回答