SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Standard Deviation


Standard Deviation

Author
Message
jkelly
jkelly
Old Hand
Old Hand (355 reputation)Old Hand (355 reputation)Old Hand (355 reputation)Old Hand (355 reputation)Old Hand (355 reputation)Old Hand (355 reputation)Old Hand (355 reputation)Old Hand (355 reputation)

Group: General Forum Members
Points: 355 Visits: 210
Comments posted to this topic are about the item Standard Deviation



Koen Verbeeck
Koen Verbeeck
SSC-Dedicated
SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)

Group: General Forum Members
Points: 35093 Visits: 13270
Nice question, really learned something.
The BOL page doesn't even mention this subject.


How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
sharath.chalamgari
sharath.chalamgari
SSCommitted
SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)

Group: General Forum Members
Points: 1650 Visits: 798
I think the Explanation is bit confusing.

if you give any numeric value to the function without any from clause it will give NULL.
SELECT STDEV(100)



"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."

example in my PackageTable the standard deveation of pa_rates column can find using

select stdev(pa_Rates) From Package



for the above Query i will get some result

but if i cange the Query with some where condition,where i will get only one Row (sample) then the stdevp will results the null value

select stdev(pa_Rates) From Package where pa_PackageID = 1


Koen Verbeeck
Koen Verbeeck
SSC-Dedicated
SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)

Group: General Forum Members
Points: 35093 Visits: 13270
sharath.chalamgari (1/28/2011)

but if i cange the Query with some where condition,where i will get only one Row (sample) then the stdevp will results the null value

select stdev(pa_Rates) From Package where pa_PackageID = 1




The WHERE clause is executed first, so you are still calculating the variance over 1 row, hence the NULL.


How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
sharath.chalamgari
sharath.chalamgari
SSCommitted
SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)

Group: General Forum Members
Points: 1650 Visits: 798
Koen (da-zero) (1/28/2011)
sharath.chalamgari (1/28/2011)

but if i cange the Query with some where condition,where i will get only one Row (sample) then the stdevp will results the null value

select stdev(pa_Rates) From Package where pa_PackageID = 1




The WHERE clause is executed first, so you are still calculating the variance over 1 row, hence the NULL.


Ya that's what i have explained above.
Koen Verbeeck
Koen Verbeeck
SSC-Dedicated
SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)

Group: General Forum Members
Points: 35093 Visits: 13270
sharath.chalamgari (1/28/2011)
Koen (da-zero) (1/28/2011)
sharath.chalamgari (1/28/2011)

but if i cange the Query with some where condition,where i will get only one Row (sample) then the stdevp will results the null value

select stdev(pa_Rates) From Package where pa_PackageID = 1




The WHERE clause is executed first, so you are still calculating the variance over 1 row, hence the NULL.


Ya that's what i have explained above.


Then why is the explanation confusing? I find it pretty clear...


How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
M&M
M&M
SSCarpal Tunnel
SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)

Group: General Forum Members
Points: 4199 Visits: 3911
Thanks for introducing new topic. I had not heard about it before

M&M
mdv 9731
mdv 9731
SSC Rookie
SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)

Group: General Forum Members
Points: 37 Visits: 126
I do not agree that the answer is right.
Think it is supposed to be 0.

the standard deviation σ (sigma) is the square root of the average value of (X − μ)2.

Which means σ = sqrt(((1-1)^2)/1) = 0

Or in other words std. deviation equals sqrt of (population-avarage) sq / number of population values

Please correct me if im wrong on the formula it has been a while since i used my statistics :-D
Koen Verbeeck
Koen Verbeeck
SSC-Dedicated
SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)

Group: General Forum Members
Points: 35093 Visits: 13270
mdv 9731 (1/28/2011)
I do not agree that the answer is right.
Think it is supposed to be 0.

the standard deviation σ (sigma) is the square root of the average value of (X − μ)2.

Which means σ = sqrt(((1-1)^2)/1) = 0

Or in other words std. deviation equals sqrt of (population-avarage) sq / number of population values

Please correct me if im wrong on the formula it has been a while since i used my statistics :-D


Even if your statistics say it is 0, SQL Server returns NULL, so the answer is still correct.
You can verify it by running the query in SQL Server Management Studio.


How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
mdv 9731
mdv 9731
SSC Rookie
SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)

Group: General Forum Members
Points: 37 Visits: 126
I'm not really going to comment on that answer.
Just happy you are not creating any kind of BI og reporting in our company :-)

I might be wrong but i still question the result.
Even if i know that it doesnt make much practical sence to talk deviation on 1 value.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search