首页 > 数据库技术 > 详细

Mysql8.0的新特点:with声明

时间:2020-01-03 16:03:12      阅读:93      评论:0      收藏:0      [点我收藏+]

Mysql8.0的新特点with声明

https://dev.mysql.com/doc/refman/8.0/en/with.html

也叫做common table expression。(CTE)

CTE是一个命名的临时结果集合,用在一个声明的内部,可以被多次反复使用。相当于一个块。

 

本文只是简单的介绍一下。

CTE的用途就是优化查询sql的方法。见这篇文章:Section 8.2.2.4, “Optimizing Derived Tables, View References, and Common Table Expressions with Merging or Materialization”.

 

Common Table Expressions

使用with子句和1个或几个逗号分隔的子句。每个子句提供一个子查询,子查询产生一个结果集合,给这个集合设置一个名字。例子:

mysql> with
    -> sc_60 as (select * from SC where score >= 60)
    -> select * from sc_60;
+------+------+-------+
| SId  | CId  | score |
+------+------+-------+
| 01   | 01   |  80.0 |
| 01   | 02   |  90.0 |
| 01   | 03   |  99.0 |
| 02   | 01   |  70.0 |
| 02   | 02   |  60.0 |
| 02   | 03   |  80.0 |
| 03   | 01   |  80.0 |
| 03   | 02   |  80.0 |
| 03   | 03   |  80.0 |
| 05   | 01   |  76.0 |
| 05   | 02   |  87.0 |
| 07   | 02   |  89.0 |
| 07   | 03   |  98.0 |
+------+------+-------+
13 rows in set (0.00 sec)

Mysql8.0的新特点:with声明

原文:https://www.cnblogs.com/chentianwei/p/12145280.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!