REGR_COUNT
REGR_COUNT(Y, X)
Section titled “REGR_COUNT(Y, X)”- y: This is the dependent variable in the regression equation. It is the variable whose values will be predicted or explained in relation with another variable, referred to as X in this function.
- x: This is the independent variable in the regression equation. It is the variable that is used to predict or explain changes in the dependent variable, Y, in this function. This is the variable that is manipulated to see if it has an effect on Y.
Example
Section titled “Example”SELECT REGR_COUNT(salary, commission_pct) OVER () AS regr_countFROM employees;Output
Section titled “Output”REGR_COUNT----------------14Explanation
Section titled “Explanation”The REGR_COUNT function returns the number of non-null pairs of numbers in a group. In this example, it returns the count of non-null pairs of salary and commission_pct from the employees table.
The basic signature for the REGR_COUNT function in PostgreSQL is as follows:REGR_COUNT(Y, X)
Section titled “The basic signature for the REGR_COUNT function in PostgreSQL is as follows:REGR_COUNT(Y, X)”- y: This parameter represents the dependent variable in the regression equation. It can be any numeric data type that PostgreSQL supports. The function calculates the number of pairs (Y,X) where Y is not null.
- x: This parameter signifies the independent variable in the regression line equation. Similar to Y, it can also be any numeric data type recognized by PostgreSQL. The function counts the pairs (Y,X) where X is not null.
Example
Section titled “Example”SELECT REGR_COUNT(weight, height) OVER() FROM humans;Output
Section titled “Output”+---------------------+| regr_count |+---------------------+| 100 |+---------------------+Explanation
Section titled “Explanation”In the above example, the REGR_COUNT function is used to count the pairs of numbers without NULL values in the “weight” and “height” columns of the “humans” table. The OVER() function specifies that the count should be done over the entire set of rows. If there are 100 non-NULL pairs of numbers, it will return 100.