All pages
Powered by GitBook
1 of 1

Loading...

STDDEV_POP

Calculate population standard deviation. This function computes the standard deviation assuming the set of values represents the entire population.

Syntax

Description

Returns the population standard deviation of expr (the square root of ). You can also use or , which are equivalent but not standard SQL.

It is an , and so can be used with the clause.

STDDEV_POP() can be used as a .

STDDEV_POP() returns NULL if there were no matching rows.

Examples

As an :

As a :

See Also

  • (equivalent, non-standard SQL)

  • (equivalent, Oracle-compatible non-standard SQL)

  • (variance)

  • (sample standard deviation)

This page is licensed: GPLv2, originally from

STDDEV_POP(expr)
VAR_POP()
STD()
STDDEV()
aggregate function
GROUP BY
window function
aggregate function
window function
STD
STDDEV
VAR_POP
STDDEV_SAMP
fill_help_tables.sql
CREATE OR REPLACE TABLE stats (category VARCHAR(2), x INT);

INSERT INTO stats VALUES 
  ('a',1),('a',2),('a',3),
  ('b',11),('b',12),('b',20),('b',30),('b',60);

SELECT category, STDDEV_POP(x), STDDEV_SAMP(x), VAR_POP(x) 
  FROM stats GROUP BY category;
+----------+---------------+----------------+------------+
| category | STDDEV_POP(x) | STDDEV_SAMP(x) | VAR_POP(x) |
+----------+---------------+----------------+------------+
| a        |        0.8165 |         1.0000 |     0.6667 |
| b        |       18.0400 |        20.1693 |   325.4400 |
+----------+---------------+----------------+------------+
CREATE OR REPLACE TABLE student_test (name CHAR(10), test CHAR(10), score TINYINT);

INSERT INTO student_test VALUES 
    ('Chun', 'SQL', 75), ('Chun', 'Tuning', 73), 
    ('Esben', 'SQL', 43), ('Esben', 'Tuning', 31), 
    ('Kaolin', 'SQL', 56), ('Kaolin', 'Tuning', 88), 
    ('Tatiana', 'SQL', 87);

SELECT name, test, score, STDDEV_POP(score) 
  OVER (PARTITION BY test) AS stddev_results FROM student_test;
+---------+--------+-------+----------------+
| name    | test   | score | stddev_results |
+---------+--------+-------+----------------+
| Chun    | SQL    |    75 |        16.9466 |
| Chun    | Tuning |    73 |        24.1247 |
| Esben   | SQL    |    43 |        16.9466 |
| Esben   | Tuning |    31 |        24.1247 |
| Kaolin  | SQL    |    56 |        16.9466 |
| Kaolin  | Tuning |    88 |        24.1247 |
| Tatiana | SQL    |    87 |        16.9466 |
+---------+--------+-------+----------------+