-->
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.  [ 2 posts ] 
Author Message
 Post subject: avg() function excluding zeroes
PostPosted: Thu Mar 04, 2010 9:46 am 
Newbie

Joined: Tue Feb 03, 2009 2:49 pm
Posts: 4
Is there any possibility of using the avg() function excluding zeroes?

I know there is a funciton excludeZeroes() but using Criteria example.

I have this hql:

Code:
"select competitorAnalyse.competitor.id,competitorAnalyse.competitor.name,avg(qualiScore.value),avg(quantiScore.value) from " + Opportunity.class.getName() + " as opp inner join opp.competitorAnalyses competitorAnalyse inner join competitorAnalyse.qualitativeScores qualiScore inner join competitorAnalyse.quantitativeScores quantiScore where opp.id = :id group by competitorAnalyse.competitor.id,competitorAnalyse.competitor.name "


and I would like to ignore the qualiScore.value and quantiScore.value values of 0

Any ideas? Pleaase help me

_________________
Leandro Iriarte. Systems Engineer
http://www.leandroiriarte.com.ar


Top
 Profile  
 
 Post subject: Re: avg() function excluding zeroes
PostPosted: Thu Mar 04, 2010 4:39 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
The avg() function will only ignore null values so the solution is to convert 0 to null. This can be done with the CASE statement:

Code:
avg(case qualiScore.value
when 0 then null
else qualiScore.value
end case)


And similar for quantiScore.value.


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