-->
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: hql max of count
PostPosted: Wed Jul 09, 2008 11:05 am 
Newbie

Joined: Thu Apr 24, 2008 7:43 pm
Posts: 6
I'm trying to get the max value of a count. There are two ways I can find to do it. The first is just do a count and then sort in desc order on the count(*). This will not work for me because I am using an older version of mysql (4.0) that doesn't allow for functions to be used in the order by clause. I have re-written the query (in sql) to

Code:

Select count(voteId) from vote group by videoId having count(voteId)=(Select max(A.CNT) from (Select count(videoId) as CNT from vote group by (videoId)) as A)



I'm trying to convert this to HQL but am having trouble with the max(A.CNT) part. Here is what I have so far

Code:
select count(*), v.video from Vote v where v.category.id=? and v.voteDate >= ? and v.voteDate <= ? group by v.video.id having count(*)=(select max(parent.child) from (select count(*) as child from Vote vo group by (vo.video.id)) as parent)


This query does not work. Any idea what I'm doing wrong? Is there is an alternate soultion to this?

Thanks
Tim


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.