Name

STDDEV_SAMP

Use STDDEV_SAMP to find the sample standard deviation within a group of numeric values.

ANSI SQL Standard Syntax

STDDEV_SAMP(numeric_expression)

MySQL and PostgreSQL

MySQL and PostgreSQL support the ANSI SQL syntax.

Oracle

Oracle supports the standard syntax. It also provides the STDDEV function, which operates similarly to STDDEV_SAMP except that it returns zero (instead of NULL) when there is only one value in the set.

Oracle also supports analytic syntax:

STDDEV_SAMP(numeric_expression) OVER (window_clause)

For an explanation of the window_clause, see the section later in this chapter titled “ANSI SQL Window Functions.”

SQL Server

Use STDEV (with only one D!).

Example

The following example computes the sample standard deviation for the values 1, 2, and 3:

SELECT * FROM test;
         X
----------
         1
         2
         3

SELECT STDDEV_SAMP(x) FROM test;
STDDEV_SAMP(X)
--------------
             1

Get SQL in a Nutshell, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.