Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Does Avg include blank entries?

Author  Topic 

sqlchiq
Posting Yak Master

133 Posts

Posted - 2008-09-05 : 17:02:56
lets say I do

select avg(somecolumn)
from thething

thething:

somecolumn
1
2

10


is the average (1+2+0+10)/4

or does it do (1+2+10)/3
??

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-09-05 : 17:08:19
It took me about 45 seconds to type this and test it, longer than it'll take to post a thread:

create table thething(somecolumn int null)

insert into thething values(1)
insert into thething values(2)
insert into thething values(NULL)
insert into thething values(10)

select avg(somecolumn)
from thething

drop table thething

It returns 4.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-06 : 23:36:24
it avoids NULL values. This is clearly defined in books online.

http://doc.ddart.net/mssql/sql70/aa-az_15.htm

and if you're having a blank value instead of NULL then that means your field type is of type character.In that case i would like to ask why u r having character field for storing numeric values.
Go to Top of Page
   

- Advertisement -