2013-11-29 40 views
0

我有这样的HQL count语句

(case app.test when 2 then '' end) as tested 

我想引用此文件http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html_single/#queryhql-aggregation

count (case app.test when 2 then 'tested' end) as tested 

这个我以后后得到这个app.state所以这样写的计数代码得到错误像

unexpected token: case 

任何想法

但是同样的语句工作的MySQL

COUNT(CASE WHEN app.test= 2 THEN "tested" END) 'tested', 
+0

的解决方案,我不认为HQL允许ü使用聚合函数的情况下计算..ü可能有使用sql查询。看看[这](http://stackoverflow.com/questions/7068051/case-statement-in-hql-or-criteria?answertab=votes#tab-top) –

+0

没有hql允许聚合函数。我已经使用它们 – Deepak

回答

0

我发现

sum(case when app.test=2 then 1 else 0 end) as tested 
0
Select count(app.state) as Confirmed from App app where app.state=2 
+0

感谢你的努力,但在这里我必须申请计数是个案陈述是问题 –