All Products
Search
Document Center

STDDEV_POP

Last Updated: Jun 18, 2021

The STDDEV_POP function calculates population standard deviation. The STDDEV_POP function uses numeric data as parameters and returns numeric data.

Notice

The population standard deviation is the arithmetic square root of a population variance.

Syntax

STDDEV_POP([ALL] expr) [ OVER (analytic_clause) ]

If the function is used as an analytic function, you must use the full syntax of a window function. The function calculates a set of rows and returns multiple values. If the function is used as an aggregate function, the function aggregates a set of rows and returns only one value. In this case, you do not need to add the OVER keyword.

Parameters

Parameter

Description

ALL

All the numeric columns.

OVER

Uses the OVER clause to define a window for calculation.

expr

The expression of the numeric data types: NUMBER, FLOAT, BINARY_FLOAT, and BINARY_DOUBLE.

Return type

The return type is the same as the data type of the expr parameter.

Examples

Examples of the analytic function

The following statements create the employees table and insert data into the table:

CREATE TABLE employees (manager_id INT,last_name varchar(50),hiredate varchar(50),SALARY INT);
INSERT INTO employees VALUES(100, 'Raphaely', '2017-07-01', 1700);
INSERT INTO employees VALUES(100, 'De Haan', '2018-05-01',11000);      
INSERT INTO employees VALUES(100, 'Errazuriz', '2017-07-21', 1400);
INSERT INTO employees VALUES(100, 'Hartstein', '2019-05-01',14000);     
INSERT INTO employees VALUES(100, 'Raphaely', '2017-07-22', 1700);
INSERT INTO employees VALUES(100, 'Weiss',  '2019-07-11',13500);     
INSERT INTO employees VALUES(100, 'Russell', '2019-10-05', 13000);
INSERT INTO employees VALUES(100, 'Partners',  '2018-12-01',14000);     
INSERT INTO employees VALUES(200, 'Ross',  '2019-06-11',13500);     
INSERT INTO employees VALUES(200, 'Bell', '2019-05-25', 13000);
INSERT INTO employees VALUES(200, 'Part',  '2018-08-11',14000);   
COMMIT;

Call the function and execute the following statement:

SELECT manager_id, last_name, salary, STDDEV_POP(salary) OVER (PARTITION BY manager_id) AS pop_std
FROM employees ORDER BY manager_id, last_name, salary, pop_std;

The following query result is returned:

+------------+-----------+--------+-------------------------------------------+
| MANAGER_ID | LAST_NAME | SALARY | POP_STD                                   |
+------------+-----------+--------+-------------------------------------------+
|        100 | De Haan   |  11000 | 5637.250548804798333699350384281939588505 |
|        100 | Errazuriz |   1400 | 5637.250548804798333699350384281939588505 |
|        100 | Hartstein |  14000 | 5637.250548804798333699350384281939588505 |
|        100 | Partners  |  14000 | 5637.250548804798333699350384281939588505 |
|        100 | Raphaely  |   1700 | 5637.250548804798333699350384281939588505 |
|        100 | Raphaely  |   1700 | 5637.250548804798333699350384281939588505 |
|        100 | Russell   |  13000 | 5637.250548804798333699350384281939588505 |
|        100 | Weiss     |  13500 | 5637.250548804798333699350384281939588505 |
|        200 | Bell      |  13000 |  408.248290463863016366214012450981899069 |
|        200 | Part      |  14000 |  408.248290463863016366214012450981899069 |
|        200 | Ross      |  13500 |  408.248290463863016366214012450981899069 |
+------------+-----------+--------+-------------------------------------------+

Examples of the aggregate function

Call the function and execute the following statement:

SELECT STDDEV_POP(salary) FROM employees ;

The following query result is returned:

+-------------------------------------------+
| STDDEV_POP(SALARY)                        |
+-------------------------------------------+
| 5249.950806538512715446505486136315088416 |
+-------------------------------------------+