-->
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.  [ 5 posts ] 
Author Message
 Post subject: count on group by
PostPosted: Mon Jun 14, 2004 4:53 am 
Newbie

Joined: Mon Mar 01, 2004 7:41 am
Posts: 6
I'm trying to do something like this:

I've got a cat table, each cat can belong to a certain type of cat, I would like to do a select where I group by cat.type and also count the number of cats that belong to each type.

Has anyone done something like this before?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 14, 2004 12:47 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
select count(cat), cat.type from Cat cat group by cat.type

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 17, 2004 1:55 am 
Newbie

Joined: Mon Mar 01, 2004 7:41 am
Posts: 6
Thank you. It's so simple and so powerfull, I love it!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 17, 2004 2:36 am 
Newbie

Joined: Wed May 12, 2004 3:17 pm
Posts: 11
i am in search of this kind of HQL...
i can get the results by giving the query as
"select count(cat), cat.type from Cat cat group by cat.type"..

but i want to get the results in console like...

CatType Counts
--------- --------
type1 5
type2 7
...
...

like this...

Collection cats = catImpl.getCatByQuery(catQry); // is it right here?
java.util.ArrayList aList = new java.util.ArrayList(cats );

System.out.println("CatType Counts");
System.out.println("--------- --------");

for(int o=0;o<aList.size();o++) {
//i can get the results here ...but not the values...
// i couldnt get those onjects/values here...
}

can anyone gimme a solution for this...

how to get the COUNT(*) and ONE PROPERTY in a single query?

any points and tips will be highly appreciated.

-NewBie(totally?)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 21, 2004 7:43 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Please read this part of the doc
http://www.hibernate.org/hib_docs/reference/en/html_single/#manipulatingdata-scalarqueries

_________________
Emmanuel


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

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.