-->
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: Average of a count
PostPosted: Mon Sep 21, 2009 11:48 am 
Newbie

Joined: Mon Sep 21, 2009 11:41 am
Posts: 1
Hello,

I'm a newbie with hql and I've encoutered a problem. I know how to make an average of a count in Sql but I can't make it in Hql.

Here's an example :

An object Cat with a color and a name.

If I want the number of cats of each color, I can make :
Code:
select count(cat.color) from Cat cat group by cat.color


But now, I want the average number of cat by colors. May someone tell me how to do this.

It's kind of something like :
Code:
select avg(count) from (select count(cat.color) as count from Cat cat group by cat.color)


But in Hql, it's perfectly wrong...


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.