where ¯x =
Pn
i=1 xi
n . As it is shown in statistics, the sample variance is an
unbiased estimator of the theoretical variance.
Example 5.19.1 To determine the population variance for the grade popula-
tion of each student we group the records of GRADES on the student number
and then compute the population variance for each group. This is done by the
following select phrase:
select stno, var_pop(grade)
from GRADES
group by stno;
select var_pop(grade)
from GRADES;
which gives:
VAR_POP(GRADE)
--------------
275.283447
A similar select
select var_samp(grade)
from GRADES;
produces the sample variance for the entire table:
VAR_SAMP(GRADE)
---------------
289.047619
If the set of values of the sample contains one value, then the function
var samp returns a null value. This is the case in the query:
select var_samp(grade)
from GRADES
where stno= ’1011’ and cno = ’cs110’
and year = 1999;
which yields:
VAR_SAMP(GRADE)
---------------
On another hand, a similar function called variance returns 0 whenever the
population contains a single value; otherwise, variance returns the sample
variance. For instance, the query
select variance(grade)
from GRADES
where stno =’1011’ and cno = ’cs110’
and year =1999;
The population standard deviation and the sample standard deviation that are
the square roots of the population and the sample variance, respectively, can be
computed using the functions stddev pop and stddev samp, respectively.
Example 5.19.2 To compute the population standard deviation of the set of
values of the grade for each student we write:
The population and the sample covariances between the values that appear
under the attributes T.A and S.B are computed using the functions covar pop
and covar samp, respectively, as in the following select phrases:
select covar_pop(T.A,S.B) from T,S where T.C = S.D;
select covar_samp(T.A,S.B) from T,S where T.C = S.D;
Example 5.19.3 The table sstudy contains whose creation was described in
Appendix B records the number of hours slept during three successive nights