Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Find AVG : Exclude values which are 0 while finding AVG

$
0
0

Hi,

I have a SQL Logic like I have mentioned below.

 case 
       when ( [ParameterName] = @ParamName  OR  [ParameterName] = @ParamName3 OR [ParameterName]=@ParamName4  OR [ParameterName]=@ParamName5) THEN   
       CAST(AVG( ( ISNULL([1],0) + ISNULL([2],0) + ISNULL([3],0)))as DECIMAL(18,2))/3   

Now I want to find AVG of values of only >0 , ie if any of the above values are 0 I want to exclude it from the AVG .

like for eg: (1+0+4) then I must be able to AVg = (1+4)/2

OTHERWISE 1+3+4 THEN avg= (1+3+4)/3

tHANKS in advance

-pep


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>