update image link

This commit is contained in:
mba1398
2021-07-01 22:42:14 +08:00
committed by GitHub
parent 90d2b7eff3
commit f6fa5edd15

View File

@@ -44,7 +44,7 @@ CREATE VIEW <视图名称>(<列名1>,<列名2>,...) AS <SELECT语句>
视图不仅可以基于真实表,我们也可以在视图的基础上继续创建视图。
![图片](https://uploader.shimo.im/f/lpBdy6SjY7FwbpsC.png!thumbnail)
![图片](https://github.com/datawhalechina/team-learning-sql/blob/main/img/ch03/ch03.02view2.png)
*图片来源《sql基础教程第2版》*
@@ -79,7 +79,7 @@ SELECT product_type, COUNT(*)
```
创建的视图如下图所示:
![图片](https://uploader.shimo.im/f/RmwfAMC3H2FlJazf.png!thumbnail)
![图片](https://github.com/datawhalechina/team-learning-sql/blob/main/img/ch03/ch03.03view3.png)
* 基于多表的视图
@@ -96,7 +96,7 @@ SELECT product_type, sale_price, shop_name
```
创建的视图如下图所示
![图片](https://uploader.shimo.im/f/7fifOiOMfOgfqrOp.png!thumbnail)
![图片](https://github.com/datawhalechina/team-learning-sql/blob/main/img/ch03/ch03.04view4.png)
我们可以在这个视图的基础上进行查询
@@ -108,7 +108,7 @@ SELECT sale_price, shop_name
```
查询结果为:
![图片](https://uploader.shimo.im/f/Y0Jf0hzxQOXCQsUp.png!thumbnail)
![图片](https://github.com/datawhalechina/team-learning-sql/blob/main/img/ch03/ch03.05result.png)
## 3.1.5 如何修改视图结构
@@ -134,7 +134,7 @@ ALTER VIEW productSum
```
此时productSum视图内容如下图所示
![图片](https://uploader.shimo.im/f/U7c1MZRuoUuHyFcj.png!thumbnail)
![图片](https://github.com/datawhalechina/team-learning-sql/blob/main/img/ch03/ch03.06productsum.png)
## 3.1.6 如何更新视图内容
@@ -163,11 +163,11 @@ UPDATE productsum
```
此时我们再查看productSum视图可以发现数据已经更新了
![图片](https://uploader.shimo.im/f/9fCOadE9zuEZS9WI.png!thumbnail)
![图片](https://github.com/datawhalechina/team-learning-sql/blob/main/img/ch03/ch03.07productsum2.png)
此时观察原表也可以发现数据也被更新了
![图片](https://uploader.shimo.im/f/5wmjMqRztHrCGiKe.png!thumbnail)
![图片](https://github.com/datawhalechina/team-learning-sql/blob/main/img/ch03/ch03.08productsumsrc.png)
不知道大家看到这个结果会不会有疑问刚才修改视图的时候是设置product_type='办公用品'的商品的sale_price=5000为什么原表的数据只有一条做了修改呢
@@ -291,7 +291,7 @@ SELECT product_type, product_name, sale_price
```
你能理解这个例子在做什么操作么?先来看一下这个例子的执行结果
![图片](https://uploader.shimo.im/f/sRdkXBxMgxT8mQYj.png!thumbnail)
![图片](https://github.com/datawhalechina/team-learning-sql/blob/main/img/ch03/ch03.09case.png)
通过上面的例子我们大概可以猜到吗,关联子查询就是通过一些标志将内外两层的查询连接起来起到过滤数据的目的,接下来我们就一起看一下关联子查询的具体内容吧。
@@ -578,7 +578,7 @@ LOWER 函数只能针对英文字母使用,它会将参数中的字符串全
使用 SUBSTRING 函数 可以截取出字符串中的一部分字符串。截取的起始位置从字符串最左侧开始计算索引值起始为1。
![图片](https://uploader.shimo.im/f/rlYYZNMWCnUbbMI4.png!thumbnail)
![图片](https://github.com/datawhalechina/team-learning-sql/blob/main/img/ch03/ch03.10function.png)
* **扩展内容SUBSTRING_INDEX -- 字符串按索引截取**
@@ -1317,11 +1317,11 @@ SELECT SUM(CASE WHEN product_type = '衣服' THEN sale_price ELSE 0 END) AS sum_
假设有如下图表的结构
![图片](https://uploader.shimo.im/f/3LtdAT7R7SCzdMPL.png!thumbnail)
![图片](https://github.com/datawhalechina/team-learning-sql/blob/main/img/ch03/ch03.11casewhen1.png)
计划得到如下的图表结构
![图片](https://uploader.shimo.im/f/4dpP0XrmPlaxr6K8.png!thumbnail)
![图片](https://github.com/datawhalechina/team-learning-sql/blob/main/img/ch03/ch03.12casewhen2.png)
聚合函数 + CASE WHEN 表达式即可实现该转换