STDDEV_SAMP (Sample Standard Deviation)
Description
The STDDEV_SAMP function calculates the sample standard deviation of a set of numeric data. Standard deviation is a statistical measure of data dispersion, used to indicate the degree of variation in a set of values. This function can handle various numeric types including TINYINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, and DECIMAL.
Parameter Description
expr: A column or expression of numeric type, includingTINYINT,SMALLINT,INT,BIGINT,FLOAT,DOUBLE, orDECIMAL.DISTINCT: Optional parameter. When set toDISTINCT, the function calculates the standard deviation of the distinct set. IfDISTINCTis not set, the function calculates the standard deviation of the set including duplicate values.
Return Result
- Returns a
DOUBLEtype value representing the sample standard deviation of the dataset. - If the input dataset contains
NULLvalues, theNULLvalues will not participate in the calculation.
Usage Examples
Example 1: Basic usage
Example 2: Using the DISTINCT keyword
Example 3: Using the FILTER clause to conditionally calculate the sample standard deviation
Example 4: Combining FILTER clause and DISTINCT to calculate the conditional sample standard deviation
With the above examples, you can better understand the usage and application scenarios of the STDDEV_SAMP function. In actual data analysis, this function can help you quickly assess the dispersion of data, thereby providing a basis for decision-making.
