The COVAR_POP Function in Oracle SQL / PLSQL is used to calculate the population covariance of a set of numbers in pair.
Syntax for the using the COVAR_POP Function in Oracle SQL / PLSQL is:
SELECT COVAR_POP(expression_1, expression_2)
FROM table_name;
- expression_1 and expression_2 are numeric expressions
- The COVAR_POP function in Oracle SQL / PLSQL will eliminate all the pairs where expression_1 and expression_2 are having NULL values.
Examples:
Using COVAR_POP Function in Oracle SQL / PLSQL SELECT statement:
Suppose we have a table named ‘employee’ as shown below:
Employee_ID | Employee_Name | Salary | Department | Commission |
101 | Emp A | 10000 | Sales | |
102 | Emp B | 20000 | IT | 20 |
103 | Emp C | 28000 | IT | 20 |
104 | Emp D | 30000 | Support | |
105 | Emp E | 32000 | Sales | 10 |
106 | Emp F | 40000 | Sales | 10 |
107 | Emp G | 12000 | Sales | 10 |
108 | Emp H | 12000 | Support |
If we write our COVAR_POP Function query as:
SELECT COVAR_POP(salary, commission) FROM employee;
We will get ‘-6000’ as output