// aggregates reference

SQL REGR_INTERCEPT function

Returns the y-intercept of the least-squares line fitted to the complete (y, x) pairs.

类别
Aggregates
Returns
numeric
In this category
29 of 52

语法

REGR_INTERCEPT(y, x) | REGR_INTERCEPT(y, x) OVER (...)

引擎支持

引擎Support备注
SQL Server Not built in same manual route
PostgreSQL 是 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 是 Supported under this name.

示例

PostgreSQL

SELECT regr_intercept(sales, ad_spend) FROM monthly;

Oracle

SELECT REGR_INTERCEPT(sales, ad_spend) FROM monthly;

值得了解

  • 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.

Cheat sheets for the engines that have it: PostgreSQL, Oracle.

// fewer lookups

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.