-->
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.  [ 3 posts ] 
Author Message
 Post subject: where clause on sums?
PostPosted: Tue Dec 12, 2006 4:26 pm 
Beginner
Beginner

Joined: Mon Jun 19, 2006 4:10 pm
Posts: 27
I am using hibernate 2.x in windows.

need to select a count(*) From table t WHERE (sum(t.a) + sum(t.b) + sum(t.c)) > 0

is that possible?

thanx


Top
 Profile  
 
 Post subject: HAVING clause
PostPosted: Tue Dec 12, 2006 5:57 pm 
Beginner
Beginner

Joined: Thu Apr 27, 2006 12:19 pm
Posts: 33
Location: Seattle, WA
I did something similar with Hibernate 3.2 which worked:

select sum(t.a), sum(t.b), sum(t.c), t.d From table t GROUP BY t.d HAVING (sum(t.a) + sum(t.b) + sum(t.c)) > 0

You probably just need to change your WHERE clause to a HAVING clause, otherwise you may get an exception: An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING clause or a select list, and the column being aggregated is an outer reference.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 12, 2006 6:00 pm 
Beginner
Beginner

Joined: Mon Jun 19, 2006 4:10 pm
Posts: 27
select count(*) from table t where (t.a + t.b + t.c) > 0

worked.

now what about select sum(t.a) + sum(t.b) + sum(t.c)....hopefully can find a way to get that gong...

edit: ya

select sum(t.a + t.b + t.c) from table t where (t.a + t.b + t.c) > 0

that was alot of worrying for nothing....


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