Chapter 20 – Statistical Aggregate Functions

“You can make more friends in two months by becoming interested in other people than you will in two years by trying to get other people interested in you."

- Dale Carnegie

The Stats Table

image

Above is the Stats_Table data that we will use in our statistical examples.

STDDEV

The query below returns the sample standard deviation for the Daily_Sales column in the Sales_Table. The Daily_Sales column is a DECIMAL. The scale of the result is reduced to 10 digits.

SELECT CAST(STDDEV(Daily_Sales) as dec(18,10))

FROM Sales_Table ;

stddev

----------------------

13389.6235806995

Casting STDDEV_SAMP and SQRT (VAR_SAMP)

The query below returns both the sample standard deviation and the square root of the sample variance for the Daily_Sales column in the Sales_Table. Notice that the result of these calculations are the same.

image

The STDDEV_POP Function

SELECT STDDEV_POP(col1)   AS SDPCol1

FROM Stats_Table;

The standard deviation function is a statistical measure of spread or dispersion of values. It is the root’s square of the difference of the mean (average). This measure is to compare the amount by which a set of values differs from the arithmetical mean.

The STDDEV_POP function is one of two that calculates the standard deviation. The population is of all the rows included based on the comparison in the WHERE clause.

Syntax for using STDDEV_POP:

STDDEV_POP(<column-name>)

A STDDEV_POP Example

image

The STDDEV_SAMP Function

SELECT STDDEV_SAMP(col1)   AS SDSCol1

FROM Stats_Table;

The standard deviation function is a statistical measure of spread or dispersion of values. It is the root’s square of the difference of the mean (average). This measure is to compare the amount by which a set of values differs from the arithmetical mean.

The STDDEV_SAMP function is one of two that calculates the standard deviation. The sample is a random selection of all rows returned based on the comparisons in the WHERE clause. The population is for all of the rows based on the WHERE clause.

Syntax for using STDDEV_SAMP:

STDDEV_SAMP(<column-name>)

A STDDEV_SAMP Example

image

The VAR_POP Function

SELECT VAR_POP(col1) AS VPCol1

FROM Stats_Table;

The Variance function is a measure of dispersion (spread of the distribution) as the square of the standard deviation. There are two forms of Variance in Matrix, VAR_POP is for the entire population of data rows allowed by the WHERE clause.

Although standard deviation and variance are regularly used in statistical calculations, the meaning of variance is not easy to elaborate. Most often variance is used in theoretical work where a variance of the sample is needed.

There are two methods for using variance. These are the Kruskal-Wallis one-way Analysis of Variance and Friedman two-way Analysis of Variance by rank.

Syntax for using VAR_POP:

VAR_POP(<column-name>)

A VAR_POP Example

image

The VAR_SAMP Function

SELECT VAR_SAMP(col1) AS VSCol1

FROM Stats_Table;

The Variance function is a measure of dispersion (spread of the distribution) as the square of the standard deviation. There are two forms of Variance in Matrix, VAR_SAMP is used for a random sampling of the data rows allowed through by the WHERE clause.

Although standard deviation and variance are regularly used in statistical calculations, the meaning of variance is not easy to elaborate. Most often variance is used in theoretical work where a variance of the sample is needed to look for consistency.

There are two methods for using variance. These are the Kruskal-Wallis one-way Analysis of Variance and Friedman two-way Analysis of Variance by rank.

Syntax for using VAR_SAMP:

VAR_SAMP(<column-name>)

A VAR_SAMP Function

image

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.81.48