-->
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: Division by Zero
PostPosted: Fri Nov 27, 2009 8:48 am 
Newbie

Joined: Fri Nov 27, 2009 8:40 am
Posts: 1
Hi There,

I'm writing a HQL query that basically says:

Select poco.A, sum(poco.B) / sum(poco.C) from Poco poco
group by poco.A
order by sum(poco.B) / sum(poco.C);

The problem is that if some groups of records have zero values for Sum(C), then we get a divide by zero error. How could I work round this in HQL?

I know I could manually do the division once I've got the results, but there are several million records and I only need the top 20, hence the "Order By" clause (along with SetMaxResults(20) used later).

Any help would be much appreciated!

Thanks,

Huw


Top
 Profile  
 
 Post subject: Re: Division by Zero
PostPosted: Fri Nov 27, 2009 10:15 am 
Regular
Regular

Joined: Mon Aug 07, 2006 5:07 am
Posts: 56
Don't know for sure, but can't you do something like this in HQL?

Code:
Select poco.A, sum(poco.B) / sum(poco.C) from Poco poco
group by poco.A
having sum(poco.C) != 0
order by sum(poco.B) / sum(poco.C);


Let me know ... :-)


Top
 Profile  
 
 Post subject: Re: Division by Zero
PostPosted: Mon Nov 30, 2009 9:50 am 
Pro
Pro

Joined: Tue Aug 26, 2003 8:07 pm
Posts: 229
Location: Brisbane, Australia
Quote:
How could I work round this in HQL?


How would you get around it in SQL?

_________________
Cheers,
Shorn.


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.