Þjálfun
Eining
Use built-in functions and GROUP BY in Transact-SQL - Training
Use built-in functions and GROUP BY in Transact-SQL
Þessi vafri er ekki lengur studdur.
Uppfærðu í Microsoft Edge til að nýta þér nýjustu eiginleika, öryggisuppfærslur og tæknilega aðstoð.
Athugasemd
Aðgangur að þessari síðu krefst heimildar. Þú getur prófað aðskrá þig inn eða breyta skráasöfnum.
Aðgangur að þessari síðu krefst heimildar. Þú getur prófað að breyta skráasöfnum.
regr_avgx
aggregate functionApplies to: Databricks SQL
Databricks Runtime 11.3 LTS and above
Returns the mean of xExpr
calculated from values of a group where xExpr
and yExpr
are NOT NULL
.
regr_avgx( [ALL | DISTINCT] yExpr, xExpr) [FILTER ( WHERE cond ) ]
This function can also be invoked as a window function using the OVER
clause.
yExpr
: A numeric expression, the dependent variable.xExpr
: A numeric expression, the independent variable.cond
: An optional Boolean expression filtering the rows used for the function.The result type depends on the type of xExpr
:
DECIMAL(p, s)
: The result type is a DECIMAL(p + 4, s + 4)
. If the maximum precision for DECIMAL
is reached the increase in scale will be limited to avoid loss of significant digits.DOUBLE
.Any nulls within the group are ignored. If a group is empty or consists only of nulls, the result is NULL
.
If DISTINCT
is specified the average is computed after duplicates have been removed.
regr_avgx(y, x)
is a synonym for avg(x) FILTER(WHERE x IS NOT NULL AND y IS NOT NULL)
.
> SELECT regr_avgx(y, x) FROM VALUES (1, 2), (2, 3), (2, 3), (null, 4), (4, null) AS T(y, x);
1.6666666666666665
Þjálfun
Eining
Use built-in functions and GROUP BY in Transact-SQL - Training
Use built-in functions and GROUP BY in Transact-SQL