MySQL Forums
Forum List  »  Newbie

Sample Standard Deviation function within views
Posted by: Mark Hillier
Date: September 30, 2015 09:38AM

Does anyone know why the Sample Standard Deviation
(Stddev_Samp) built in function works OK when used as a simple select
query but when used as part of a view it returns the population
standard deviation.

It seems to occur on both Windows and Linux versions of MySQL.
Has anyone else found this? Am I doing some thing
wrong or is it a bug.

In this example MyValue contains the numbers 1,2,3,4 & 5.
The Select query below correctly finds the mean, population
and sample standard deviations.

mysql> select avg(myvalue), stddev_pop(myvalue), stddev_samp(myvalue) from mytable;
+--------------+---------------------+----------------------+
| avg(myvalue) | stddev_pop(myvalue) | stddev_samp(myvalue) |
+--------------+---------------------+----------------------+
| 3 | 1.4142135623730951 | 1.5811388300841898 |
+--------------+---------------------+----------------------+
1 row in set (0.00 sec)

But when the function is made into a view then it returns the population
value when executed as shown below.

mysql> Create view myView as
select avg(myvalue), stddev_pop(myvalue), stddev_samp(myvalue) from mytable;

mysql> select * from myview;
+--------------+---------------------+----------------------+
| avg(myvalue) | stddev_pop(myvalue) | stddev_samp(myvalue) |
+--------------+---------------------+----------------------+
| 3 | 1.4142135623730951 | 1.4142135623730951 |
+--------------+---------------------+----------------------+
1 row in set (0.00 sec)

Options: ReplyQuote


Subject
Written By
Posted
Sample Standard Deviation function within views
September 30, 2015 09:38AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.