> ## Documentation Index
> Fetch the complete documentation index at: https://clickhouse.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

> 返回各变量与其平均值之差的乘积之和。

# regr_sxy

<h2 id="regr_sxy">
  regr\_sxy
</h2>

引入版本：v26.9.0

返回两个变量的离差乘积之和：

$$
\Sigma{(x - \bar{x})(y - \bar{y})}
$$

**语法**

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

**别名**：`regrSXY`

**参数**

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

**返回值**

返回 `x` 和 `y` 相对于各自平均值的离差乘积之和。 [`Float64`](/docs/reference/data-types/float)

**示例**

**基本用法**

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

```response title=响应 theme={null}
┌─regr_sxy(y, x)─┐
│             10 │
└────────────────┘
```
