Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

StDev() function returns Null when table contains only one row

I am trying to use the StDev function and am getting blank results. I am using it as...

SELECT StDev(fldMean) FROM myTable

Where fldMean contains a value of 2.3 and should evaluate to 0 but instead I am simply getting an empty result. I can't seem to understand how expressions are to be used in the function, Microsoft's manual really didn't help.

like image 720
codingManiac Avatar asked Jan 05 '14 17:01

codingManiac


People also ask

Why is the standard deviation null?

if you give any numeric value to the function without any from clause it will give NULL. "The STDEV function uses all of the values to calculate the standard deviation. There must be at least two values in the field or the standard deviation will not be calculated and a NULL is returned."

What is Stdev function in SQL?

The STDEV function computes the standard deviation for the selected rows. It is the square root of the VARIANCE function. You can apply the STDEV function only to numeric columns.

Does select count return null?

COUNT never returns null. The following example calculates, for each employee in the employees table, the moving count of employees earning salaries in the range 50 less than through 150 greater than the employee's salary.


1 Answers

SELECT StDev(fldMean) FROM myTable

will return Null if [myTable] has only one row because the Standard Deviation cannot be computed from a single observation. You will need at least two rows in that table before you can receive a meaningful result. If you want to force the Null value to zero you can use

SELECT Nz(StDev(fldMean), 0) FROM myTable
like image 102
Gord Thompson Avatar answered Oct 22 '22 17:10

Gord Thompson