日期:2014-05-18  浏览次数:20802 次

帮忙hql问题
sql:

select   A.v_num,B.*   from   (select   count(*)   v_num,max(jsp_rootid)   jsp_rootid1  
from   jsp_userpost   where   jsp_forum= '1 '   and   jsp_rootid   <> '0 '   group   by   jsp_rootid   )  
A   right   join   (select   *   from   jsp_userpost   where   jsp_forum= '1 '   and   jsp_rootid= '0 '   )B  
on   A.jsp_rootid1   =   B.jsp_postid   order   by   B.jsp_posttime   desc  

hql:

String   sql   =   "from   (select   count(*)   num,max(jspRootid)   jsp_rootid1   "+
"   from   jspUserpost   where   jspForum= '1 '   and   jspRootid   <> '0 '   group   by   jspRootid   )   "+  
"   A   right   join   (select   *   from   jspUserpost   where   jspForum= '1 '   and   jspRootid= '0 '   )B   "+  
"   on   A.jsp_rootid1   =   B.jspPostid   order   by   B.jspPosttime   desc   ";

hql要怎么写
jspUserpost是一个table的映射,我还要加上返回的num
请问这个hql要怎么写?

------解决方案--------------------
HQL不支持from中的子查询,如果太复杂可以在数据库中建一个子查询的视图,在HQL中from这个视图