-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: SQL to HQL help
PostPosted: Mon Sep 05, 2011 10:03 pm 
Newbie

Joined: Sat May 07, 2011 9:56 pm
Posts: 7
Hi,

I have a fairly complex join query that I wrote in native SQL (using mysql) that I am trying to rewrite in standard HQL to be db agnostic but am having a lot of difficulties. For starters, HQL does not seem to support limit statements other than in query.criteria settings, but I have to join against a sub-select with a limit. So I really am not sure how to accomplish this.

Can anyone help please?
Code:

      select * from player as p join (
            select p.last_login, ps.player_id, count(sv.hit) as total_votes, sum(sv.hit) as votes, sum(sv.hit)/count(sv.hit)*100 as percentage, count(sv.hit) + sum(sv.hit)/count(sv.hit) as score
             from snapshot as s join snapshot_vote as sv on (s.id = sv.snapshot) join player_snapshot as ps on (s.id=ps.snapshot_id) join player p on (ps.player_id = p.id)
             group by ps.player_id
             order by score desc limit 0, :topPlayerPoolSize
         )  as topScores
         having  last_login > date_sub( now(), interval :lastLoginDays day ) and player_id not in
                (select player_id from trend_leader_article where date_issued > date_sub( now(), interval :lastTrendLeaderMonths month ) )
         order by rand() limit 0,1;



Any help or suggestions are would be greatly appreciated!

Thanks,

Eric


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.