博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
sql视图_SQL视图
阅读量:2506 次
发布时间:2019-05-11

本文共 1423 字,大约阅读时间需要 4 分钟。

sql视图

An interesting thing you can do with SQL is to create a view.

使用SQL可以做的一件有趣的事情是创建一个视图

A view is like a table, except instead of being a real table, on its own, it is dynamically built by the result of a SELECT query.

视图就像一个表,除了它本身不是真实的表之外,它是由SELECT查询的结果动态构建的。

Let’s use the example we used in the joins lesson:

让我们使用在连接课程中使用的示例:

CREATE TABLE people (  age INT NOT NULL,  name CHAR(20) NOT NULL PRIMARY KEY);CREATE TABLE cars (  brand CHAR(20) NOT NULL,  model CHAR(20) NOT NULL,  owner CHAR(20) NOT NULL PRIMARY KEY);

We add some data:

我们添加一些数据:

INSERT INTO people VALUES (37, 'Flavio');INSERT INTO people VALUES (8, 'Roger');INSERT INTO cars VALUES ('Ford', 'Fiesta', 'Flavio');INSERT INTO cars VALUES ('Ford', 'Mustang', 'Roger');

We can create a view that we call car_age that always contains the correlation between a car model and its owner’s age:

我们可以创建一个称为car_age的视图,该视图始终包含汽车模型与其所有者年龄之间的相关性:

CREATE VIEW car_age AS SELECT model, age AS owner_age FROM people JOIN cars ON people.name = cars.owner;

Here is the result we can inspect with SELECT * FROM car_age:

这是我们可以使用SELECT * FROM car_age检查的结果:

model         | owner_age ----------------------+----------- Fiesta               |        37 Mustang              |         8

The view is persistent, and will look like a table in your database. You can delete a view using DROP VIEW:

该视图是持久性的,看起来像数据库中的表。 您可以使用DROP VIEW删除DROP VIEW

DROP VIEW car_age

翻译自:

sql视图

转载地址:http://shmgb.baihongyu.com/

你可能感兴趣的文章
FFmpeg 新旧版本编码 API 的区别
查看>>
RecyclerView 源码深入解析——绘制流程、缓存机制、动画等
查看>>
Android 面试题整理总结(一)Java 基础
查看>>
Android 面试题整理总结(二)Java 集合
查看>>
学习笔记_vnpy实战培训day02
查看>>
学习笔记_vnpy实战培训day03
查看>>
VNPY- VnTrader基本使用
查看>>
VNPY - CTA策略模块策略开发
查看>>
VNPY - 事件引擎
查看>>
MongoDB基本语法和操作入门
查看>>
学习笔记_vnpy实战培训day04_作业
查看>>
OCO订单(委托)
查看>>
学习笔记_vnpy实战培训day06
查看>>
回测引擎代码分析流程图
查看>>
Excel 如何制作时间轴
查看>>
matplotlib绘图跳过时间段的处理方案
查看>>
vnpy学习_04回测评价指标的缺陷
查看>>
设计模式10_桥接
查看>>
量化策略回测DCCV2
查看>>
mongodb查询优化
查看>>