Solved

How can I take standard deviation in MYsql?

Posted on 2008-11-03
1,350 Views
I have two columns containing two different timestamps for particular user. How can I calculate Standard deviation for this.

Is there any direct function available to perform this like sum() or avg()
0
Question by:saini_er

LVL 17

Expert Comment

You have the STDDEV() function... Not sure if that's what you need: http://dev.mysql.com/doc/refman/5.1/en/group-by-functions.html#function_stddev
0

LVL 31

Assisted Solution

Look into the STD(), or  STDDEV_POP() aggregate functions in mysql.

http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_std
0

LVL 26

Assisted Solution

0

Author Comment

Thanks guys for reply.....All of these methods are for finding standard deviation population where one value is randomly picked from table and then used as average..

I s there any function which can give regualr standard deviation whch is generally found by calculating exact mean
0

LVL 26

Expert Comment

0

LVL 31

Expert Comment

mysql supports STD() which is population standard deviation, and STDDEV_SAMP() which returns the sample standard deviation. Not sure but maybe the sample deviation is what you're looking for.

Alternatively you can do it manually using some variables. You can nest the aggregate functions in MySQL But I think if you get the average first and store it in a variable, you can do the rest. E.g. something like:

SELECT @ln_average := AVG(total) FROM yourtable;
SELECT (1/COUNT(total)) * SUM( POW(total - @ln_average,2) )  FROM yourtable;
0

LVL 31

Expert Comment

"You can nest the aggregate functions in MySQL"

Sorry, you CAN'T nest the aggregate functions in MySQL.
0

Accepted Solution

I don't  think there is any direct fuction . so I am going by mathematic expression and calculate result out of it
0

Featured Post

Loading csv or delimited data files to MySQL database is a very common task frequently questioned about and almost every time LOAD DATA INFILE comes to the rescue. Here we will try to understand some of the very common scenarios for loading data …
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video discusses moving either the default database or any database to a new volume.