-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1176 from yangj1211/apply
add doc of apply
- Loading branch information
Showing
4 changed files
with
84 additions
and
9 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
docs/MatrixOne/Reference/SQL-Reference/Data-Query-Language/apply/cross-apply.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# **CROSS APPLY** | ||
|
||
## **语法说明** | ||
|
||
`CROSS APPLY` 是 MatrixOne 中的一个特殊连接操作符,主要用于将一个表的每一行与另一个返回结果集的表函数(如表值函数)进行连接。与 JOIN 不同,CROSS APPLY 允许右侧的子查询或表值函数依赖于左侧表的每一行,从而为每一行返回不同的结果。 | ||
|
||
## **语法结构** | ||
|
||
``` | ||
> SELECT <columns> | ||
FROM <table_name> | ||
CROSS APPLY <table_function> <alias>; | ||
``` | ||
|
||
## **示例** | ||
|
||
```sql | ||
mysql> create table t1(a int, b int); | ||
Query OK, 0 rows affected (0.03 sec) | ||
|
||
mysql> insert into t1 values(1,3),(1,-1); | ||
Query OK, 2 rows affected (0.00 sec) | ||
|
||
mysql> select * from t1 cross apply generate_series(t1.a,t1.b,1)g; | ||
+------+------+--------+ | ||
| a | b | result | | ||
+------+------+--------+ | ||
| 1 | 3 | 1 | | ||
| 1 | 3 | 2 | | ||
| 1 | 3 | 3 | | ||
+------+------+--------+ | ||
3 rows in set (0.02 sec) | ||
``` |
34 changes: 34 additions & 0 deletions
34
docs/MatrixOne/Reference/SQL-Reference/Data-Query-Language/apply/outer-apply.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# **OUTER APPLY** | ||
|
||
## **语法说明** | ||
|
||
`OUTER APPLY` 是用来将主表的每一行与一个函数或子查询的结果动态关联的。(右侧内容可以基于主表的行动态生成)。与 [`CROSS APPLY`](./cross-apply.md) 不同的是,即使右侧没有数据,也不会丢弃主表的记录,只是右侧列用 NULL 填充。(类似 LEFT JOIN 的效果,但右侧是动态生成的数据)。 | ||
|
||
## **语法结构** | ||
|
||
``` | ||
> SELECT <columns> | ||
FROM <table_name> | ||
outer APPLY <table_function><alias>; | ||
``` | ||
|
||
## **示例** | ||
|
||
```sql | ||
mysql> create table t1(a int, b int); | ||
Query OK, 0 rows affected (0.03 sec) | ||
|
||
mysql> insert into t1 values(1,3),(1,-1); | ||
Query OK, 2 rows affected (0.00 sec) | ||
|
||
mysql> select * from t1 outer apply generate_series(t1.a,t1.b,1)g; | ||
+------+------+--------+ | ||
| a | b | result | | ||
+------+------+--------+ | ||
| 1 | 3 | 1 | | ||
| 1 | 3 | 2 | | ||
| 1 | 3 | 3 | | ||
| 1 | -1 | NULL | | ||
+------+------+--------+ | ||
4 rows in set (0.01 sec) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters