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

Average Function Not Working as Expected

$
0
0

If you try the following code without the zero, it returns the correct average of 1. 

Add the zero, and it returns the incorrect average of 0.

Is it me? Why?

DECLARE @Test AS TABLE(n INTEGER)
INSERT INTO @Test VALUES(1),(1),(1),(1),(1),(0),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1),(1)
SELECT 
AVG(n) AS [n Average],
SUM(n) AS [n Sum] 
FROM 
@Test



+__+


Viewing all articles
Browse latest Browse all 23857

Trending Articles



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