求改hql hql 语句不支持from后面直接跟子查询表
wbsmm 2009-05-11 03:00:42 我想统计该生在该章节的 *做题总数* 中的排行
select count(1) from (select count(*) as con from test_log where chapter_id=12 group by user_id) as a where a.con>= (select count(*) from test_log where user_id=3 and chapter_id=12);
在mysql数据库中能够查询到结果
在hibernate中,return (Integer)this.getHibernateTemplate().find("select count(*) from (select count(1) as con from TestLog where chapterId="+chapterId+" group by userId) as a where a.con>= (select count(*) from TestLog where userId="+userId+" and chapterId="+chapterId+")").get(0);
报出错误信息:
[ERROR]http-8082-4-org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/superteacher1.0].[action]-Servlet.service() for servlet action threw exception
org.hibernate.hql.ast.QuerySyntaxException: unexpected token: ( near line 1, column 22 [select count(*) from (select count(1) as con from hibernate.dao.TestLog where chapterId=2 group by userId) as a where a.con>= (select count(*) from hibernate.dao.TestLog where userId=9 and chapterId=2)]
好像是不识别from后面是个子查询表,哪位高手能把我这个hql语句改改~~~