我想统计该生在该章节的 *做题总数* 中的排行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语句改改~~~
在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语句改改~~~
解决方案 »
- 我用 java写的 akka zeromq 看不到效果,pubSocket发送的message subSocket 不能够收到,请高手解答一下。
- 学struts1 还是学struts2?
- Tomcat6.0如何启动时设置JVM的大小
- 不显示删除回复显示所有回复显示星级回复显示得分回复 jboss下部署项目不能访问本身Lib的jar包问题??
- Tomcat下的工程如何在weblogic下发布?
- 关于Spring的xslt视图显示问题
- 这条SQL语句,用hibernate怎么写啊?
- petstore流程
- 一个初次在jbuilder8开发EJB的问题?
- 求java生成xml文件的例子
- 急!5000左右笔记本电脑推荐!
- 大家来谈谈对非数值计算的理解?
想想能否构造一个sql满足需求,又绕过这一限制的语句。
直接传语句select count(*),user_id from test_log where chapter_id=12 group by user_id order by count(*) desc;
然后出来之后就是一个list里面两个元素count(*)和user_id。遍历list当中的user_id,这个user第几个被遍历到,就是第几名了。