> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-vortex-format.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> 返回回归直线的斜率。

# regr_slope

<h2 id="regr_slope">
  regr\_slope
</h2>

引入版本：v26.9.0

返回 `y` 对 `x` 的最小二乘拟合的斜率：

$$
\frac{\Sigma{(x - \bar{x})(y - \bar{y})}}{\Sigma{(x - \bar{x})^2}}
$$

当 `x` 为常量时返回 `nan`，因为此时拟合直线垂直于 x 轴。

**语法**

```sql theme={null}
regr_slope(y, x)
```

**别名**：`regrSlope`

**参数**

* `y` — 因变量。 [`(U)Int*`](/reference/data-types/int-uint) 或 [`Float*`](/reference/data-types/float)
* `x` — 自变量。 [`(U)Int*`](/reference/data-types/int-uint) 或 [`Float*`](/reference/data-types/float)

**返回值**

返回回归直线的斜率。 [`Float64`](/reference/data-types/float)

**示例**

**基本用法**

```sql title=Query theme={null}
SELECT regr_slope(y, x)
FROM VALUES('x Float64, y Float64', (1, 2), (2, 4), (3, 6), (4, 8))
```

```response title=Response theme={null}
┌─regr_slope(y, x)─┐
│                2 │
└──────────────────┘
```
