Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs](function) support aggregrate function regr_slope regr_intercept #1167

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
{
"title": "REGR_INTERCEPT",
"language": "en"
}
---

## Description
REGR_INTERCEPT is used to calculate the y-intercept of the least squares-fit linear equation for a set of number pairs.

## Syntax
```
REGR_INTERCEPT(y, x)
```

## Parameters
- `y` (Numeric): The dependent variable.
- `x` (Numeric): The independent variable.

Both `x` and `y` support basic numeric types.

## Returned values
Returned data type: FLOAT64

The function returns the y-intercept of the linear regression line.

If there are no rows, or only rows with null values, the function returns NULL.

## Examples
```sql
-- Example 1: Basic Usage
SELECT regr_intercept(y, x) FROM test;

-- Example 2: Usage in a query with sample data
SELECT * FROM test;
+------+------+------+
| id | x | y |
+------+------+------+
| 1 | 18 | 13 |
| 3 | 12 | 2 |
| 5 | 10 | 20 |
| 2 | 14 | 27 |
| 4 | 5 | 6 |
+------+------+------+

SELECT regr_intercept(y, x) FROM test;
+----------------------+
| regr_intercept(y, x) |
+----------------------+
| 5.512931034482759 |
+----------------------+
```

## Usage notes
- This function ignores any pair where either value is null.
- In cases where the calculation would result in a division by zero, the function will return NULL.

## Related functions
REGR_SLOPE, REGR_R2, REGR_COUNT, REGR_AVGX, REGR_AVGY

## References
For more details about linear regression functions, please refer to the SQL standard documentation on aggregate functions.
62 changes: 62 additions & 0 deletions docs/sql-manual/sql-functions/aggregate-functions/regr_slope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
{
"title": "REGR_SLOPE",
"language": "en"
}
---

## Description
REGR_SLOPE is used to calculate the slope of the least squares-fit linear equation for a set of number pairs.

## Syntax
```
REGR_SLOPE(y, x)
```

## Parameters
- `y` (Numeric): The dependent variable.
- `x` (Numeric): The independent variable.

Both `x` and `y` support basic numeric types.

## Returned values
Returned data type: FLOAT64

The function returns the slope of the linear regression line.

If there are no rows, or only rows with null values, the function returns NULL.

## Examples
```sql
-- Example 1: Basic Usage
SELECT regr_slope(y, x) FROM test;

-- Example 2: Usage in a query with sample data
SELECT * FROM test;
+------+------+------+
| id | x | y |
+------+------+------+
| 1 | 18 | 13 |
| 3 | 12 | 2 |
| 5 | 10 | 20 |
| 2 | 14 | 27 |
| 4 | 5 | 6 |
+------+------+------+

SELECT regr_slope(y, x) FROM test;
+--------------------+
| regr_slope(y, x) |
+--------------------+
| 0.6853448275862069 |
+--------------------+
```

## Usage notes
- This function ignores any pair where either value is null.
- In cases where the calculation would result in a division by zero, the function will return NULL.

## Related functions
REGR_INTERCEPT, REGR_R2, REGR_COUNT, REGR_AVGX, REGR_AVGY

## References
For more details about linear regression functions, please refer to the SQL standard documentation on aggregate functions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
{
"title": "REGR_INTERCEPT",
"language": "zh-CN"
}
---

## Description
REGR_INTERCEPT 用于计算一组数值对的最小二乘拟合线性方程的截距。

## Syntax
```
REGR_INTERCEPT(y, x)
```

## Parameters
- `y` (数值类型):因变量。
- `x` (数值类型):自变量。

x 和 y 都支持基本数值类型。

## Returned values
返回数据类型:FLOAT64

函数返回线性回归直线的截距。

如果没有行,或者只有包含空值的行,函数返回 NULL。

## Examples
```sql
-- 示例 1:基本用法
SELECT regr_intercept(y, x) FROM test;

-- 示例 2:在查询中使用示例数据
SELECT * FROM test;
+------+------+------+
| id | x | y |
+------+------+------+
| 1 | 18 | 13 |
| 3 | 12 | 2 |
| 5 | 10 | 20 |
| 2 | 14 | 27 |
| 4 | 5 | 6 |
+------+------+------+

SELECT regr_intercept(y, x) FROM test;
+----------------------+
| regr_intercept(y, x) |
+----------------------+
| 5.512931034482759 |
+----------------------+
```

## Usage notes
- 此函数会忽略任何包含空值的数值对。
- 在计算结果会导致除以零的情况下,函数将返回 NULL。

## Related functions
REGR_SLOPE, REGR_R2, REGR_COUNT, REGR_AVGX, REGR_AVGY

## References
有关线性回归函数的更多详细信息,请参阅 SQL 标准文档中关于聚合函数的部分。
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
{
"title": "REGR_SLOPE",
"language": "zh-CN"
}
---

## Description
REGR_SLOPE 用于计算一组数值对的最小二乘拟合线性方程的斜率。

## Syntax
```
REGR_SLOPE(y, x)
```

## Parameters
- `y` (数值类型):因变量。
- `x` (数值类型):自变量。

x 和 y 都支持基本数值类型。

## Returned values
返回数据类型:FLOAT64

函数返回线性回归直线的斜率。

如果没有行,或者只有包含空值的行,函数返回 NULL。

## Examples
```sql
-- 示例 1:基本用法
SELECT regr_slope(y, x) FROM test;

-- 示例 2:在查询中使用示例数据
SELECT * FROM test;
+------+------+------+
| id | x | y |
+------+------+------+
| 1 | 18 | 13 |
| 3 | 12 | 2 |
| 5 | 10 | 20 |
| 2 | 14 | 27 |
| 4 | 5 | 6 |
+------+------+------+

SELECT regr_slope(y, x) FROM test;
+--------------------+
| regr_slope(y, x) |
+--------------------+
| 0.6853448275862069 |
+--------------------+
```

## Usage notes
- 此函数会忽略任何包含空值的数值对。
- 在计算结果会导致除以零的情况下,函数将返回 NULL。

## Related functions
REGR_INTERCEPT, REGR_R2, REGR_COUNT, REGR_AVGX, REGR_AVGY

## References
有关线性回归函数的更多详细信息,请参阅 SQL 标准文档中关于聚合函数的部分。
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
{
"title": "REGR_INTERCEPT",
"language": "zh-CN"
}
---

## Description
REGR_INTERCEPT 用于计算一组数值对的最小二乘拟合线性方程的截距。

## Syntax
```
REGR_INTERCEPT(y, x)
```

## Parameters
- `y` (数值类型):因变量。
- `x` (数值类型):自变量。

x 和 y 都支持基本数值类型。

## Returned values
返回数据类型:FLOAT64

函数返回线性回归直线的截距。

如果没有行,或者只有包含空值的行,函数返回 NULL。

## Examples
```sql
-- 示例 1:基本用法
SELECT regr_intercept(y, x) FROM test;

-- 示例 2:在查询中使用示例数据
SELECT * FROM test;
+------+------+------+
| id | x | y |
+------+------+------+
| 1 | 18 | 13 |
| 3 | 12 | 2 |
| 5 | 10 | 20 |
| 2 | 14 | 27 |
| 4 | 5 | 6 |
+------+------+------+

SELECT regr_intercept(y, x) FROM test;
+----------------------+
| regr_intercept(y, x) |
+----------------------+
| 5.512931034482759 |
+----------------------+
```

## Usage notes
- 此函数会忽略任何包含空值的数值对。
- 在计算结果会导致除以零的情况下,函数将返回 NULL。

## Related functions
REGR_SLOPE, REGR_R2, REGR_COUNT, REGR_AVGX, REGR_AVGY

## References
有关线性回归函数的更多详细信息,请参阅 SQL 标准文档中关于聚合函数的部分。
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
{
"title": "REGR_SLOPE",
"language": "zh-CN"
}
---

## Description
REGR_SLOPE 用于计算一组数值对的最小二乘拟合线性方程的斜率。

## Syntax
```
REGR_SLOPE(y, x)
```

## Parameters
- `y` (数值类型):因变量。
- `x` (数值类型):自变量。

x 和 y 都支持基本数值类型。

## Returned values
返回数据类型:FLOAT64

函数返回线性回归直线的斜率。

如果没有行,或者只有包含空值的行,函数返回 NULL。

## Examples
```sql
-- 示例 1:基本用法
SELECT regr_slope(y, x) FROM test;

-- 示例 2:在查询中使用示例数据
SELECT * FROM test;
+------+------+------+
| id | x | y |
+------+------+------+
| 1 | 18 | 13 |
| 3 | 12 | 2 |
| 5 | 10 | 20 |
| 2 | 14 | 27 |
| 4 | 5 | 6 |
+------+------+------+

SELECT regr_slope(y, x) FROM test;
+--------------------+
| regr_slope(y, x) |
+--------------------+
| 0.6853448275862069 |
+--------------------+
```

## Usage notes
- 此函数会忽略任何包含空值的数值对。
- 在计算结果会导致除以零的情况下,函数将返回 NULL。

## Related functions
REGR_INTERCEPT, REGR_R2, REGR_COUNT, REGR_AVGX, REGR_AVGY

## References
有关线性回归函数的更多详细信息,请参阅 SQL 标准文档中关于聚合函数的部分。
2 changes: 2 additions & 0 deletions sidebars.json
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,8 @@
"sql-manual/sql-functions/aggregate-functions/collect-set",
"sql-manual/sql-functions/aggregate-functions/collect-list",
"sql-manual/sql-functions/aggregate-functions/retention",
"sql-manual/sql-functions/aggregate-functions/regr_intercept",
"sql-manual/sql-functions/aggregate-functions/regr_slope",
"sql-manual/sql-functions/aggregate-functions/regr_sxx",
"sql-manual/sql-functions/aggregate-functions/regr_sxy",
"sql-manual/sql-functions/aggregate-functions/regr_syy",
Expand Down
Loading