-2

我有以下用 HQL 为 Hibernate 编写的查询。

==================================================== =======================

select new map(ret.retailerDesc as ret_name, ret.id.retailerId as ret_id,
               ret.id.serviceId as service_id,  

(select count(distinct i.inspectionId) as inspections from Inspection i 
inner join i.clgCodeStatus c 
inner join c.retailerOrderses r  
inner join r.cusRetailer cr 
inner join i.inspectionMission m  where ret.id = cr.id  ) as inspections ,

(select count(distinct i.inspectionId) as inspections   from Inspection i 
inner join i.clgCodeStatus c 
inner join c.retailerOrderses r 
inner join r.cusRetailer cr 
inner join i.inspectionMission m 
where ret.id = cr.id  and i.inspectionResult = '1'  ) as match,

(select count(distinct i.inspectionId) as inspections   from Inspection i 
inner join i.clgCodeStatus c 
inner join c.retailerOrderses r 
inner join r.cusRetailer cr 
inner join i.inspectionMission m 
where ret.id = cr.id  and i.inspectionResult = '0'  ) as mismatch  )

from CusRetailer ret  order by inspections desc

==================================================== ======================

执行上述查询时,会出现以下错误:

ERROR: column "inspections" does not exist

它为“按检查顺序排序”给出了此错误。如果我删除它,它工作正常。

谁能帮我解决这个问题?

谢谢。

4

2 回答 2

2

您可能需要重复表达式inspections

...from CusRetailer ret order by count(distinct i.inspectionId)

可能是 HQL 不支持order by子句中的表达式,您可能需要改用 SQL 查询。

于 2009-06-09T06:38:14.850 回答
0

我在上面的查询中使用“按 col_1_0_ 排序”解决了它。因为休眠创建列名称为 col_0_0_、col_1_0_、col_2_0_ 等等。所以如果您只需要知道列的顺序并将其添加到相应的 order by 中。 .

谢谢。

amar4kintu

于 2009-12-29T12:06:27.770 回答