Skip to content

Commit

Permalink
update mysql docs
Browse files Browse the repository at this point in the history
  • Loading branch information
fengzhao committed Nov 26, 2020
1 parent f730910 commit 1ff84bf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions mysql/CTE公用表达式.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,23 @@ insert into db_test.employees_mgr values
(4610, "Sarah", 29); /* Sarah has id 4610 and reports to 29 (Pedro) */


-- 要查询出如下这种树形结果

+------+---------+--------------------+
| id | name | path |
+------+---------+--------------------+
| 333 | Yasmina | 333 |
| 198 | John | 333->198 |
| 692 | Tarek | 333->692 |
| 29 | Pedro | 333->198->29 |
| 4610 | Sarah | 333->198->29->4610 |
+------+---------+--------------------+
5 rows in set (0.00 sec)
mysql>




-- MySQL8.0中支持with子句
-- 通过递归CTE来查询用户的层级关系
-- 规划一个ID,name,path这样的一个层级临时表
Expand All @@ -99,19 +116,6 @@ insert into db_test.employees_mgr values
)
select * from employee_paths;


+------+---------+--------------------+
| id | name | path |
+------+---------+--------------------+
| 333 | Yasmina | 333 |
| 198 | John | 333->198 |
| 692 | Tarek | 333->692 |
| 29 | Pedro | 333->198->29 |
| 4610 | Sarah | 333->198->29->4610 |
+------+---------+--------------------+
5 rows in set (0.00 sec)
mysql>

```


Expand Down
Empty file.

0 comments on commit 1ff84bf

Please sign in to comment.