我在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
“检查desc”的命令给出了这个错误。 如果我删除它工作正常。
有谁可以帮我解决这个问题?
感谢。
答案 0 :(得分:2)
可能需要重复inspections
...from CusRetailer ret order by count(distinct i.inspectionId)
可能HQL不支持order by
子句中的表达式,您可能需要使用n SQL查询。
答案 1 :(得分:0)
我在上面的查询中使用“按col_1_0_命令”解决了它...因为hibernate创建了名为col_0_0_,col_1_0_,col_2_0_等的列...所以如果您只需要知道列的顺序并将其添加到订单中相应地..
感谢。
amar4kintu