SQL REGR_INTERCEPT function
Returns the y-intercept of the least-squares line fitted to the complete (y, x) pairs.
- Kategorie
- Aggregates
- Returns
numeric- In this category
- 29 of 52
Syntax
REGR_INTERCEPT(y, x) | REGR_INTERCEPT(y, x) OVER (...)
Engine-Unterstützung
| Engine | Support | Notizen |
|---|---|---|
| SQL Server | Not built in | same manual route |
| PostgreSQL | Ja | Supported under this name. |
| MySQL | Not built in | compute AVG(y) - slope * AVG(x) with the manual slope formula |
| SQLite | Not built in | No built-in equivalent. |
| Oracle | Ja | Supported under this name. |
Beispiele
PostgreSQL
SELECT regr_intercept(sales, ad_spend) FROM monthly;
Oracle
SELECT REGR_INTERCEPT(sales, ad_spend) FROM monthly;
Gut zu wissen
- Same pair filtering as the rest of the family: either input NULL drops the row.
- NULL whenever REGR_SLOPE is NULL: fewer than two pairs or zero x-variance.
- Portable form: AVG(y) - REGR_SLOPE(y, x) * AVG(x), or the fully manual formula where REGR_ is missing.
Questions about REGR_INTERCEPT
What does the intercept mean here?
The predicted y when x is 0, for the line fitted by least squares.
How do I compute it by hand?
AVG(y) - slope * AVG(x), with slope = COVAR_POP(y,x) / VAR_POP(x).
Which engines ship it?
PostgreSQL and Oracle; MySQL and SQL Server need the manual formula.
Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.
Related on SQLly
Cheat sheets for the engines that have it: PostgreSQL, Oracle.
Functions your engine actually has
SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.