Skip to content
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
2 changes: 2 additions & 0 deletions docs/sql-manual/sql-functions/aggregate-functions/max-by.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---

Check notice on line 1 in docs/sql-manual/sql-functions/aggregate-functions/max-by.md

View workflow job for this annotation

GitHub Actions / Build Check

i18n-sync-version-candidate

A 3.x counterpart exists. Confirm whether the change is supported in 3.x before leaving it unsynced. Owner%3A @apache/doris-website-maintainers
{
"title": "MAX_BY",
"language": "en",
Expand All @@ -10,6 +10,8 @@

The MAX_BY function returns the associated value based on the maximum value of the specified column.

When `<expr2>` is an Array, arrays are compared lexicographically, element by element; a NULL element is greater than any non-NULL element. A NULL array value is ignored.

## Syntax

```sql
Expand Down
2 changes: 1 addition & 1 deletion docs/sql-manual/sql-functions/aggregate-functions/max.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---

Check notice on line 1 in docs/sql-manual/sql-functions/aggregate-functions/max.md

View workflow job for this annotation

GitHub Actions / Build Check

i18n-sync-version-candidate

A 3.x counterpart exists. Confirm whether the change is supported in 3.x before leaving it unsynced. Owner%3A @apache/doris-website-maintainers

Check warning on line 1 in docs/sql-manual/sql-functions/aggregate-functions/max.md

View workflow job for this annotation

GitHub Actions / Build Check

seo-description-length

SEO description should be 80-160 characters; current length is 70. Owner%3A @apache/doris-website-maintainers
{
"title": "MAX",
"language": "en",
Expand Down Expand Up @@ -83,7 +83,7 @@
select k1, max(k_array) from t1 group by k1;
```

For Array type: Returns the maximum array value for each group(Compare elements one by one; null is the smallest element.).
For Array type: Returns the maximum array value for each group. Arrays are compared lexicographically, element by element; a NULL element is greater than any non-NULL element. A NULL array value is ignored like other NULL input values.

```text
+------+--------------+
Expand Down
2 changes: 2 additions & 0 deletions docs/sql-manual/sql-functions/aggregate-functions/min-by.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---

Check notice on line 1 in docs/sql-manual/sql-functions/aggregate-functions/min-by.md

View workflow job for this annotation

GitHub Actions / Build Check

i18n-sync-version-candidate

A 3.x counterpart exists. Confirm whether the change is supported in 3.x before leaving it unsynced. Owner%3A @apache/doris-website-maintainers
{
"title": "MIN_BY",
"language": "en",
Expand All @@ -10,6 +10,8 @@

The MIN_BY function returns the associated value based on the minimum value of the specified column.

When `<expr2>` is an Array, arrays are compared lexicographically, element by element; a NULL element is greater than any non-NULL element. A NULL array value is ignored.

## Syntax

```sql
Expand Down
2 changes: 1 addition & 1 deletion docs/sql-manual/sql-functions/aggregate-functions/min.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---

Check notice on line 1 in docs/sql-manual/sql-functions/aggregate-functions/min.md

View workflow job for this annotation

GitHub Actions / Build Check

i18n-sync-version-candidate

A 3.x counterpart exists. Confirm whether the change is supported in 3.x before leaving it unsynced. Owner%3A @apache/doris-website-maintainers

Check warning on line 1 in docs/sql-manual/sql-functions/aggregate-functions/min.md

View workflow job for this annotation

GitHub Actions / Build Check

seo-description-length

SEO description should be 80-160 characters; current length is 70. Owner%3A @apache/doris-website-maintainers
{
"title": "MIN",
"language": "en",
Expand Down Expand Up @@ -82,7 +82,7 @@
select k1, min(k_array) from t1 group by k1;
```

For Array type: Returns the minimum array value for each group(Compare elements one by one; null is the smallest element.).
For Array type: Returns the minimum array value for each group. Arrays are compared lexicographically, element by element; a NULL element is greater than any non-NULL element. A NULL array value is ignored like other NULL input values.

```text
+------+----------------+
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
---
{
"title": "ARRAY_EXCEPT_ALL",
"language": "en",
"description": "Returns the multiset difference of two arrays, preserving unmatched duplicates and the order of the first array."
}
---

## array_except_all

<version since="dev">

</version>

## Description

Returns the multiset difference of `arr1` and `arr2`. Each occurrence in `arr2` removes at most one equal occurrence from `arr1`; remaining elements, including duplicates, keep their original order. `NULL` elements are compared and removed by occurrence, while a `NULL` input array produces a `NULL` result.

## Syntax

```sql
ARRAY_EXCEPT_ALL(<arr1>, <arr2>)
```

## Parameters

| Parameter | Description |
| -- | -- |
| `<arr1>` | The first array. Its element type must be a supported scalar type and must be compatible with the element type of `<arr2>`. |
| `<arr2>` | The second array. Each occurrence removes one matching occurrence from `<arr1>`. Its element type must be a supported scalar type and must be compatible with `<arr1>`. |

Supported scalar element types include numeric, boolean, string, date/time, and IPv4/IPv6 types. Complex element types such as `ARRAY`, `MAP`, `STRUCT`, `JSON`, and `VARIANT` are not supported.

## Return Value

Returns an `ARRAY<T>` containing the remaining elements from `<arr1>` in their original order. If either input array is `NULL`, returns `NULL`. If no elements remain, returns an empty array.

## Example

Basic multiset difference:

```sql
SELECT array_except_all([1, 1, 2, 3], [1, 3]);
```

```text
[1, 2]
```

Occurrences are removed one at a time, so unmatched duplicates are preserved:

```sql
SELECT array_except_all(['a', 'a', 'b'], ['a']);
```

```text
["a", "b"]
```

The result keeps the order of the first array:

```sql
SELECT array_except_all([3, 1, 3, 2], [3]);
```

```text
[1, 3, 2]
```

`NULL` elements participate in multiset subtraction:

```sql
SELECT array_except_all(['a', NULL, 'a', NULL], [NULL]);
```

```text
["a", "a", null]
```

If either input array is `NULL`, the result is `NULL`:

```sql
SELECT array_except_all(CAST(NULL AS ARRAY<INT>), [1]);
```

```text
NULL
```

An empty second array leaves the first array unchanged:

```sql
SELECT array_except_all([1, 1, 2], CAST([] AS ARRAY<INT>));
```

```text
[1, 1, 2]
```

Unlike `array_except`, this function preserves remaining duplicates:

```sql
SELECT array_except([1, 1, 2], [1]), array_except_all([1, 1, 2], [1]);
```

```text
[2] [1, 2]
```

Complex element types are not supported:

```sql
SELECT array_except_all([[1], [2]], [[1]]);
```

```text
ERROR 1105 (HY000): array_except_all does not support types
```

### Keywords

ARRAY, EXCEPT, MULTISET, ARRAY_EXCEPT_ALL
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---

Check warning on line 1 in i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/aggregate-functions/max-by.md

View workflow job for this annotation

GitHub Actions / Build Check

seo-description-length

SEO description should be 80-160 characters; current length is 30. Owner%3A @apache/doris-website-maintainers
{
"title": "MAX_BY",
"language": "zh-CN",
Expand All @@ -10,6 +10,8 @@

MAX_BY 函数用于根据指定列的最大值,返回对应的的关联值。

当 `<expr2>` 为 Array 时,数组按字典序逐元素比较;数组元素中的 NULL 大于任何非 NULL 元素。整个数组为 NULL 时会被忽略。

## 语法

```sql
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---

Check warning on line 1 in i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/aggregate-functions/max.md

View workflow job for this annotation

GitHub Actions / Build Check

seo-description-length

SEO description should be 80-160 characters; current length is 23. Owner%3A @apache/doris-website-maintainers
{
"title": "MAX",
"language": "zh-CN",
Expand Down Expand Up @@ -82,7 +82,7 @@
select k1, max(k_array) from t1 group by k1;
```

Array 类型: 返回最大的数组值(逐元素比较大小,null为最小元素)
Array 类型:返回每组最大的数组值。数组按字典序逐元素比较;数组元素中的 NULL 大于任何非 NULL 元素。整个数组为 NULL 时,与其他 NULL 输入值一样会被忽略

```text
+------+--------------+
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---

Check warning on line 1 in i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/aggregate-functions/min-by.md

View workflow job for this annotation

GitHub Actions / Build Check

seo-description-length

SEO description should be 80-160 characters; current length is 30. Owner%3A @apache/doris-website-maintainers
{
"title": "MIN_BY",
"language": "zh-CN",
Expand All @@ -10,6 +10,8 @@

MIN_BY 函数用于根据指定列的最小值,返回对应的的关联值。

当 `<expr2>` 为 Array 时,数组按字典序逐元素比较;数组元素中的 NULL 大于任何非 NULL 元素。整个数组为 NULL 时会被忽略。

## 语法

```sql
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---

Check warning on line 1 in i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/aggregate-functions/min.md

View workflow job for this annotation

GitHub Actions / Build Check

seo-description-length

SEO description should be 80-160 characters; current length is 23. Owner%3A @apache/doris-website-maintainers
{
"title": "MIN",
"language": "zh-CN",
Expand Down Expand Up @@ -82,7 +82,7 @@
select k1, min(k_array) from t1 group by k1;
```

Array 类型: 返回最小的数组值(逐元素比较大小,null为最小元素)
Array 类型:返回每组最小的数组值。数组按字典序逐元素比较;数组元素中的 NULL 大于任何非 NULL 元素。整个数组为 NULL 时,与其他 NULL 输入值一样会被忽略

```text
+------+----------------+
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
---

Check warning on line 1 in i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/array-functions/array-except-all.md

View workflow job for this annotation

GitHub Actions / Build Check

seo-description-length

SEO description should be 80-160 characters; current length is 35. Owner%3A @apache/doris-website-maintainers
{
"title": "ARRAY_EXCEPT_ALL",
"language": "zh-CN",
"description": "返回两个数组的多重集差集,保留未匹配的重复元素及第一个数组的原始顺序。"
}
---

## array_except_all

<version since="dev">

</version>

## 描述

返回 `arr1``arr2` 的多重集差集。`arr2` 中的每个元素最多抵消 `arr1` 中一个相同的元素;未被抵消的元素(包括重复元素)按照 `arr1` 的原始顺序保留。数组元素中的 `NULL` 也按出现次数进行比较和抵消;如果任一输入数组为 `NULL`,则返回 `NULL`

## 语法

```sql
ARRAY_EXCEPT_ALL(<arr1>, <arr2>)
```

## 参数

| 参数 | 说明 |
| -- | -- |
| `<arr1>` | 第一个数组。元素必须为支持的标量类型,且必须与 `<arr2>` 的元素类型兼容。 |
| `<arr2>` | 第二个数组。其中每次出现的元素会抵消 `<arr1>` 中一个相同的元素;元素必须为支持的标量类型,且必须与 `<arr1>` 兼容。 |

支持的标量元素类型包括数值、布尔、字符串、日期时间以及 IPv4/IPv6 类型。不支持 `ARRAY``MAP``STRUCT``JSON``VARIANT` 等复杂元素类型。

## 返回值

返回 `ARRAY<T>`,包含 `<arr1>` 中剩余的元素,并保持其原始顺序。如果任一输入数组为 `NULL`,返回 `NULL`;如果没有剩余元素,返回空数组。

## 示例

基本多重集差集:

```sql
SELECT array_except_all([1, 1, 2, 3], [1, 3]);
```

```text
[1, 2]
```

元素按出现次数逐个抵消,未匹配的重复元素会保留:

```sql
SELECT array_except_all(['a', 'a', 'b'], ['a']);
```

```text
["a", "b"]
```

结果保持第一个数组的顺序:

```sql
SELECT array_except_all([3, 1, 3, 2], [3]);
```

```text
[1, 3, 2]
```

数组中的 `NULL` 参与多重集差集运算:

```sql
SELECT array_except_all(['a', NULL, 'a', NULL], [NULL]);
```

```text
["a", "a", null]
```

任一输入数组为 `NULL` 时返回 `NULL`

```sql
SELECT array_except_all(CAST(NULL AS ARRAY<INT>), [1]);
```

```text
NULL
```

第二个数组为空时,第一个数组保持不变:

```sql
SELECT array_except_all([1, 1, 2], CAST([] AS ARRAY<INT>));
```

```text
[1, 1, 2]
```

`array_except` 不同,本函数会保留剩余的重复元素:

```sql
SELECT array_except([1, 1, 2], [1]), array_except_all([1, 1, 2], [1]);
```

```text
[2] [1, 2]
```

不支持复杂元素类型:

```sql
SELECT array_except_all([[1], [2]], [[1]]);
```

```text
ERROR 1105 (HY000): array_except_all does not support types
```

### 关键词

ARRAY、EXCEPT、MULTISET、ARRAY_EXCEPT_ALL
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---

Check warning on line 1 in i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/aggregate-functions/max-by.md

View workflow job for this annotation

GitHub Actions / Build Check

seo-description-length

SEO description should be 80-160 characters; current length is 30. Owner%3A @zclllyybb
{
"title": "MAX_BY",
"language": "zh-CN",
Expand All @@ -10,6 +10,8 @@

MAX_BY 函数用于根据指定列的最大值,返回对应的的关联值。

当 `<expr2>` 为 Array 时,数组按字典序逐元素比较;数组元素中的 NULL 大于任何非 NULL 元素。整个数组为 NULL 时会被忽略。

## 语法

```sql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Decimal 类型:返回最大的高精度小数值。
select k1, max(k_array) from t1 group by k1;
```

Array 类型: 返回最大的数组值(逐元素比较大小,null为最小元素)
Array 类型:返回每组最大的数组值。数组按字典序逐元素比较;数组元素中的 NULL 大于任何非 NULL 元素。整个数组为 NULL 时,与其他 NULL 输入值一样会被忽略

```text
+------+--------------+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

MIN_BY 函数用于根据指定列的最小值,返回对应的的关联值。

当 `<expr2>` 为 Array 时,数组按字典序逐元素比较;数组元素中的 NULL 大于任何非 NULL 元素。整个数组为 NULL 时会被忽略。

## 语法

```sql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Decimal 类型:返回最小的高精度小数值。
select k1, min(k_array) from t1 group by k1;
```

Array 类型: 返回最小的数组值(逐元素比较大小,null为最小元素)
Array 类型:返回每组最小的数组值。数组按字典序逐元素比较;数组元素中的 NULL 大于任何非 NULL 元素。整个数组为 NULL 时,与其他 NULL 输入值一样会被忽略

```text
+------+----------------+
Expand Down
Loading
Loading