> ## 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_r2

<h2 id="regr_r2">
  regr\_r2
</h2>

引入版本：v26.9.0

返回最小二乘拟合的决定系数，即相关系数的平方。若 `x` 为常量，则返回 `nan`；若 `y` 为常量，则返回 `1`。

**语法**

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

**别名**：`regrR2`

**参数**

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

**返回值**

返回 0 到 1 之间的值。[`Float64`](/zh/reference/data-types/float)

**示例**

**基本用法**

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

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