Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 4729

How to calculate the Average of fields that are not zero?

$
0
0

I have a few columns: Week1, Week2, Week3, Week4, Week5

i.e. 

Week1 = 5

Week2 = 0

Week3 = 10

Week4 = 7

Week5 = 0

How do I calculate the average based on the fields that are not zero?

Incorrect:
(5+0+10+7+0)/5 = 4.4

Correct:
(5+0+10+7+0)/3 = 7.3

How to let create a custom column to let the SQL know that I only want to divide by 3 instead of 5?


Viewing all articles
Browse latest Browse all 4729

Trending Articles



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