-->
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.  [ 4 posts ] 
Author Message
 Post subject: order by children size
PostPosted: Sat Mar 24, 2007 1:46 pm 
Newbie

Joined: Sat Mar 24, 2007 1:37 pm
Posts: 3
Hibernate version:
3.2

I'm in situation that I have to list items up ordered by children's count.
Let me say parent is 'User' and children is 'Order'.

This is basic one-to-many relation.
One user can have multiple orders.

I've already finished working on mapping file and generation POJO, etc.
Then how can I get the list which tells top 10 users who place orders the most?

This can be easily done by SQL, but no idea with HQL.
I tried something like this

select count(o) from User u left join Order o group by u

then got syntax error :(

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 25, 2007 8:03 pm 
Newbie

Joined: Sat Mar 24, 2007 1:37 pm
Posts: 3
Can't this be easily solved?
Or am I not clear?


Top
 Profile  
 
 Post subject: try this
PostPosted: Mon Mar 26, 2007 2:31 am 
Beginner
Beginner

Joined: Thu Feb 01, 2007 3:08 am
Posts: 20
Instead of group by u use u.x(x is a column in u)

Try the below query

select u.username,count(o) from User u left join Order o group by u.username order by count(o) desc

Regards
Gokul


Top
 Profile  
 
 Post subject: thanks
PostPosted: Mon Mar 26, 2007 5:51 am 
Newbie

Joined: Sat Mar 24, 2007 1:37 pm
Posts: 3
thanks

it works


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.