Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
95 changes: 95 additions & 0 deletions docs/sql-manual/sql-functions/aggregate-functions/sem.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
---
{
"title": "SEM",
"language": "en"
}
---

## Description

Calculate the standard error of the mean for all non-null values in the specified column or expression.

## Syntax

```text
SEM([DISTINCT] <expr>)
```

## Parameters

| Parameter | Description |
| -- | -- |
| `<expr>` | An expression or column, typically a numeric column or an expression that can be converted to a numeric value, supporting the Double data type.|
| `[DISTINCT]` | An optional keyword indicating that the mean standard error should be calculated after removing duplicate values in expr.。 |

## Return Value

Returns a Double. Returns the standard error of the mean for the selected column or expression. If all records within the group are NULL, the function returns NULL.

## Examples

```sql
-- setup
create table t1(
id int,
k_double double,
) distributed by hash (id) buckets 1
properties ("replication_num"="1");
insert into t1 values
(1, 222.222),
(2, 3.3),
(3, 3.3),
(4, null);
```

```sql
select sem(k_double) from t1;
```

Calculation of the mean for the Double type: the mean and standard error for [222.222, 3.3, 3.3, null] is 72.974.

```text
+---------------+
| sem(k_double) |
+---------------+
| 72.974 |
+---------------+
```

```sql
select sem(cast(null as double)) from t1;
```

When all values are null, return null.

```text
+---------------------------+
| sem(cast(null as double)) |
+---------------------------+
| NULL |
+---------------------------+
```

```sql
select sem(distinct k_double) from t1;
```

Using the DISTINCT keyword for deduplication calculations, the mean standard error after removing duplicates [222.222, 3.3, 3.3, null] is 109.461.

```text
+------------------------+
| sem(distinct k_double) |
+------------------------+
| 109.461 |
+------------------------+
```

### Error example

```sql
select sem(id) from t1;
```

```text
ERROR 1105 (HY000): errCode = 2, detailMessage = sem only requires a double parameter: sem(id)
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
---
{
"title": "SEM",
"language": "zh-CN"
}
---

## 描述

计算指定列或表达式的所有非 NULL 值的均值标准误。

## 语法

```sql
SEM([DISTINCT] <expr>)
```

## 参数

| 参数 | 说明 |
| -- | -- |
| `<expr>` | 是一个表达式或列,通常是一个数值列或者能够转换为数值的表达式,支持类型为 Double。|
| `[DISTINCT]` | 是一个可选的关键字,表示对 expr 中的重复值进行去重后再计算均值标准误。 |

## 返回值

返回值为 Double。 返回所选列或表达式的均值标准误,如果组内的所有记录均为 NULL,则该函数返回 NULL 。

## 举例

```sql
-- setup
create table t1(
id int,
k_double double,
) distributed by hash (id) buckets 1
properties ("replication_num"="1");
insert into t1 values
(1, 222.222),
(2, 3.3),
(3, 3.3),
(4, null);
```

```sql
select sem(k_double) from t1;
```

Double 类型的平均值计算,[222.222,3.3,3.3,null]的均值标准误为72.974。

```text
+---------------+
| sem(k_double) |
+---------------+
| 72.974 |
+---------------+
```

```sql
select sem(cast(null as double)) from t1;
```

值全为null时,返回null。

```text
+---------------------------+
| sem(cast(null as double)) |
+---------------------------+
| NULL |
+---------------------------+
```

```sql
select sem(distinct k_double) from t1;
```

使用 DISTINCT 关键字进行去重计算,[222.222,3.3,3.3,null]去重后均值标准误为109.461。

```text
+------------------------+
| sem(distinct k_double) |
+------------------------+
| 109.461 |
+------------------------+
```

### 错误示例

```sql
select sem(id) from t1;
```

```text
ERROR 1105 (HY000): errCode = 2, detailMessage = sem only requires a double parameter: sem(id)
```
1 change: 1 addition & 0 deletions sidebars.json
Original file line number Diff line number Diff line change
Expand Up @@ -1851,6 +1851,7 @@
"sql-manual/sql-functions/aggregate-functions/regr-intercept",
"sql-manual/sql-functions/aggregate-functions/regr-slope",
"sql-manual/sql-functions/aggregate-functions/retention",
"sql-manual/sql-functions/aggregate-functions/sem",
"sql-manual/sql-functions/aggregate-functions/sequence-count",
"sql-manual/sql-functions/aggregate-functions/sequence-match",
"sql-manual/sql-functions/aggregate-functions/skew",
Expand Down