-->
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.  [ 7 posts ] 
Author Message
 Post subject: Simple question of order by aggregate function
PostPosted: Mon Jun 28, 2004 10:01 am 
Beginner
Beginner

Joined: Sun Nov 16, 2003 9:30 am
Posts: 20
Hi All ,

I have an HQL like this :
select po, avg(item.price) from foo.PO po join po.items item group by po

How can I have the po sort by avg(item.price) ?

I tried to found google but can't get the answer of this simple sql question. Please help ....

Thanks.

Perseus


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 28, 2004 10:06 am 
Beginner
Beginner

Joined: Sun Nov 16, 2003 9:30 am
Posts: 20
Sorry, something missing.

I tried :
select po, avg(item.price) from foo.PO po join po.items item group by po
order by avg(item.price).

But error message :
General error, message from server: "Invalid use of group function"

Thanks.

Perseus


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 28, 2004 10:14 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Try "group by "po.foo, po.bar" and all other properties of "po".

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 28, 2004 10:21 am 
Beginner
Beginner

Joined: Sun Nov 16, 2003 9:30 am
Posts: 20
But po has quite many properties. Is there any other simpler method ?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 28, 2004 10:25 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
No, but you are using projection anyway (a select clause), so why don't you simply select only the properties you really need?

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 28, 2004 10:27 am 
Beginner
Beginner

Joined: Sun Nov 16, 2003 9:30 am
Posts: 20
Sorry, I don't quite get what you mean.

I would need the whole object of PO rather than only some properties.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 28, 2004 10:29 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Then, group by all properties. This might be changed in a future, but it's actually a documented FAQ:

http://www.hibernate.org/74.html#A12

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


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