Skip to content

Commit dcd79bd

Browse files
authored
Support DISTINCT keyword (#663)
1 parent 607342c commit dcd79bd

File tree

4 files changed

+64
-18
lines changed

4 files changed

+64
-18
lines changed

src/UserGuide/Master/Table/SQL-Manual/Select-Clause.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,21 @@
2626
## 1. Syntax Overview
2727

2828
```sql
29-
SELECT selectItem (',' selectItem)*
29+
SELECT setQuantifier? selectItem (',' selectItem)*
3030

3131
selectItem
3232
: expression (AS? identifier)? #selectSingle
3333
| tableName '.' ASTERISK (AS columnAliases)? #selectAll
3434
| ASTERISK #selectAll
3535
;
36+
setQuantifier
37+
: DISTINCT
38+
| ALL
39+
;
3640
```
3741

3842
- It supports aggregate functions (e.g., `SUM`, `AVG`, `COUNT`) and window functions, logically executed last in the query process.
43+
- DISTINCT Keyword: `SELECT DISTINCT column_name` ensures that the values in the query results are unique, removing duplicates.
3944

4045
## 2. Detailed Syntax:
4146

@@ -45,6 +50,13 @@ Each `selectItem` can take one of the following forms:
4550
2. **All Columns from a Relation**: `relation.*` selects all columns from a specified relation. Column aliases are not allowed in this case.
4651
3. **All Columns in the Result Set**: `*` selects all columns returned by the query. Column aliases are not allowed.
4752

53+
Usage scenarios for DISTINCT:
54+
55+
1. **SELECT Statement**: Use DISTINCT in the SELECT statement to remove duplicate items from the query results.
56+
57+
2. **Aggregate Functions**: When used with aggregate functions, DISTINCT only processes non-duplicate rows in the input dataset.
58+
59+
3. **AGROUP BY Clause**: Use ALL and DISTINCT quantifiers in the GROUP BY clause to determine whether each duplicate grouping set produces distinct output rows.
4860

4961
## 3. Example Data
5062

src/UserGuide/latest-Table/SQL-Manual/Select-Clause.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,21 @@
2626
## 1. Syntax Overview
2727

2828
```sql
29-
SELECT selectItem (',' selectItem)*
29+
SELECT setQuantifier? selectItem (',' selectItem)*
3030

3131
selectItem
3232
: expression (AS? identifier)? #selectSingle
3333
| tableName '.' ASTERISK (AS columnAliases)? #selectAll
3434
| ASTERISK #selectAll
3535
;
36+
setQuantifier
37+
: DISTINCT
38+
| ALL
39+
;
3640
```
3741

3842
- It supports aggregate functions (e.g., `SUM`, `AVG`, `COUNT`) and window functions, logically executed last in the query process.
43+
- DISTINCT Keyword: `SELECT DISTINCT column_name` ensures that the values in the query results are unique, removing duplicates.
3944

4045
## 2. Detailed Syntax:
4146

@@ -45,6 +50,13 @@ Each `selectItem` can take one of the following forms:
4550
2. **All Columns from a Relation**: `relation.*` selects all columns from a specified relation. Column aliases are not allowed in this case.
4651
3. **All Columns in the Result Set**: `*` selects all columns returned by the query. Column aliases are not allowed.
4752

53+
Usage scenarios for DISTINCT:
54+
55+
1. **SELECT Statement**: Use DISTINCT in the SELECT statement to remove duplicate items from the query results.
56+
57+
2. **Aggregate Functions**: When used with aggregate functions, DISTINCT only processes non-duplicate rows in the input dataset.
58+
59+
3. **AGROUP BY Clause**: Use ALL and DISTINCT quantifiers in the GROUP BY clause to determine whether each duplicate grouping set produces distinct output rows.
4860

4961
## 3. Example Data
5062

src/zh/UserGuide/Master/Table/SQL-Manual/Select-Clause.md

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,35 @@
2424
## 1. 语法概览
2525

2626
```sql
27-
SELECT selectItem (',' selectItem)*
27+
SELECT setQuantifier? selectItem (',' selectItem)*
2828

2929
selectItem
3030
: expression (AS? identifier)? #selectSingle
3131
| tableName '.' ASTERISK (AS columnAliases)? #selectAll
3232
| ASTERISK #selectAll
3333
;
34+
setQuantifier
35+
: DISTINCT
36+
| ALL
37+
;
3438
```
3539

36-
- __SELECT 子句__: 指定了查询结果应包含的列,包含聚合函数(如 SUM、AVG、COUNT 等)以及窗口函数,在逻辑上最后执行。
40+
- **SELECT 子句**: 指定了查询结果应包含的列,包含聚合函数(如 SUM、AVG、COUNT 等)以及窗口函数,在逻辑上最后执行。
41+
- **DISTINCT 关键字**: `SELECT DISTINCT column_name` 确保查询结果中的值是唯一的,去除重复项。
3742

3843
## 2. 语法详释:
3944

4045
每个 `selectItem` 可以是以下形式之一:
4146

42-
- __表达式__: `expression [ [ AS ] column_alias ]` 定义单个输出列,可以指定列别名。
43-
- __选择某个关系的所有列__: `relation.*` 选择某个关系的所有列,不允许使用列别名。
44-
- __选择结果集中的所有列__: `*` 选择查询的所有列,不允许使用列别名。
47+
- **表达式**: `expression [ [ AS ] column_alias ]` 定义单个输出列,可以指定列别名。
48+
- **选择某个关系的所有列**: `relation.*` 选择某个关系的所有列,不允许使用列别名。
49+
- **选择结果集中的所有列**: `*` 选择查询的所有列,不允许使用列别名。
50+
51+
`DISTINCT` 的使用场景:
52+
53+
- **SELECT 语句**:在 SELECT 语句中使用 DISTINCT,查询结果去除重复项。
54+
- **聚合函数**:与聚合函数一起使用时,DISTINCT 只处理输入数据集中的非重复行。
55+
- **GROUP BY 子句**:在 GROUP BY 子句中使用 ALL 和 DISTINCT 量词,决定是否每个重复的分组集产生不同的输出行。
4556

4657
## 3. 示例数据
4758

@@ -51,7 +62,7 @@ selectItem
5162

5263
#### 3.1.1 星表达式
5364

54-
使用星号(*)可以选取表中的所有列,__注意__,星号表达式不能被大多数函数转换,除了`count(*)`的情况。
65+
使用星号(*)可以选取表中的所有列,**注意**,星号表达式不能被大多数函数转换,除了`count(*)`的情况。
5566

5667
示例:从表中选择所有列
5768

@@ -246,5 +257,5 @@ It costs 0.189s
246257

247258
## 4. 结果集列顺序
248259

249-
- __列顺序__: 结果集中的列顺序与 SELECT 子句中指定的顺序相同。
250-
- __多列排序__: 如果选择表达式返回多个列,它们的排序方式与源关系中的排序方式相同
260+
- **列顺序**: 结果集中的列顺序与 SELECT 子句中指定的顺序相同。
261+
- **多列排序**: 如果选择表达式返回多个列,它们的排序方式与源关系中的排序方式相同

src/zh/UserGuide/latest-Table/SQL-Manual/Select-Clause.md

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,35 @@
2424
## 1. 语法概览
2525

2626
```sql
27-
SELECT selectItem (',' selectItem)*
27+
SELECT setQuantifier? selectItem (',' selectItem)*
2828

2929
selectItem
3030
: expression (AS? identifier)? #selectSingle
3131
| tableName '.' ASTERISK (AS columnAliases)? #selectAll
3232
| ASTERISK #selectAll
3333
;
34+
setQuantifier
35+
: DISTINCT
36+
| ALL
37+
;
3438
```
3539

36-
- __SELECT 子句__: 指定了查询结果应包含的列,包含聚合函数(如 SUM、AVG、COUNT 等)以及窗口函数,在逻辑上最后执行。
40+
- **SELECT 子句**: 指定了查询结果应包含的列,包含聚合函数(如 SUM、AVG、COUNT 等)以及窗口函数,在逻辑上最后执行。
41+
- **DISTINCT 关键字**: `SELECT DISTINCT column_name` 确保查询结果中的值是唯一的,去除重复项。
3742

3843
## 2. 语法详释:
3944

4045
每个 `selectItem` 可以是以下形式之一:
4146

42-
- __表达式__: `expression [ [ AS ] column_alias ]` 定义单个输出列,可以指定列别名。
43-
- __选择某个关系的所有列__: `relation.*` 选择某个关系的所有列,不允许使用列别名。
44-
- __选择结果集中的所有列__: `*` 选择查询的所有列,不允许使用列别名。
47+
- **表达式**: `expression [ [ AS ] column_alias ]` 定义单个输出列,可以指定列别名。
48+
- **选择某个关系的所有列**: `relation.*` 选择某个关系的所有列,不允许使用列别名。
49+
- **选择结果集中的所有列**: `*` 选择查询的所有列,不允许使用列别名。
50+
51+
`DISTINCT` 的使用场景:
52+
53+
- **SELECT 语句**:在 SELECT 语句中使用 DISTINCT,查询结果去除重复项。
54+
- **聚合函数**:与聚合函数一起使用时,DISTINCT 只处理输入数据集中的非重复行。
55+
- **GROUP BY 子句**:在 GROUP BY 子句中使用 ALL 和 DISTINCT 量词,决定是否每个重复的分组集产生不同的输出行。
4556

4657
## 3. 示例数据
4758

@@ -51,7 +62,7 @@ selectItem
5162

5263
#### 3.1.1 星表达式
5364

54-
使用星号(*)可以选取表中的所有列,__注意__,星号表达式不能被大多数函数转换,除了`count(*)`的情况。
65+
使用星号(*)可以选取表中的所有列,**注意**,星号表达式不能被大多数函数转换,除了`count(*)`的情况。
5566

5667
示例:从表中选择所有列
5768

@@ -246,5 +257,5 @@ It costs 0.189s
246257

247258
## 4. 结果集列顺序
248259

249-
- __列顺序__: 结果集中的列顺序与 SELECT 子句中指定的顺序相同。
250-
- __多列排序__: 如果选择表达式返回多个列,它们的排序方式与源关系中的排序方式相同
260+
- **列顺序**: 结果集中的列顺序与 SELECT 子句中指定的顺序相同。
261+
- **多列排序**: 如果选择表达式返回多个列,它们的排序方式与源关系中的排序方式相同

0 commit comments

Comments
 (0)