STDEV() in SQL
Calculates the standard deviation (population or sample) of a set of numeric values.
Syntax
Return type
STDEV() Function Example
What is STDEV() in SQL?
The STDEV()
function in SQL calculates the standard deviation of a set of numeric values, measuring how much the values deviate from the mean (average). It is commonly used in statistical analysis, financial modeling, and quality control to assess variability in data.
SQL databases typically provide two types of standard deviation calculations:
Population Standard Deviation (
STDDEV_POP()
) → Measures standard deviation for an entire dataset.Sample Standard Deviation (
STDDEV_SAMP()
) → Measures standard deviation for a sample from a dataset.
This function is supported in SQL Server, PostgreSQL, MySQL (as STDDEV_POP()
and STDDEV_SAMP()
), and Oracle.
Parameters:
expression: Numeric column or expression to calculate standard deviation
Example Use Cases:
-- Calculate salary spread by department
-- Measure price variation
-- Analyze score distribution
Notes:
Behavior: Ignores NULL values in calculation
Performance Considerations: Square root of variance calculation
Version Info: Available in most major DBMS with varying syntax
Deprecated/Recommended Alternatives: None
Error Handling:
Error: Returns NULL if insufficient non-NULL values
Recommendation: Use COALESCE for NULL handling
Supported Databases:
DBMS
Function / Syntax
Example
Behavior with NULL
MySQL
STD(), STDDEV(), STDDEV_POP(), STDDEV_SAMP()
STD(salary)
Ignores NULL
PostgreSQL
STDDEV(), STDDEV_POP(), STDDEV_SAMP()
STDDEV(salary)
Ignores NULL
SQL Server
STDEV(), STDEVP()
STDEV(salary)
Ignores NULL
SQLite
STDEV()
STDEV(salary)
Ignores NULL
BigQuery
STDDEV(), STDDEV_POP(), STDDEV_SAMP()
STDDEV(salary)
Ignores NULL
Snowflake
STDDEV(), STDDEV_POP(), STDDEV_SAMP()
STDDEV(salary)
Ignores NULL
Athena
STDDEV(), STDDEV_POP(), STDDEV_SAMP()
STDDEV(salary)
Ignores NULL