当前位置:网站首页>Mysql入门学习(三)之视图
Mysql入门学习(三)之视图
2022-06-23 03:55:00 【默主归沙】
- 视图
概念: 从一张或多张表中抽取的虚拟表,操作虚拟表的CRUD与原表完全一样
优点:
1.简单化,从多张表抽取后,只需要管理虚拟表即可
2.安全性,能看到的只是抽取到虚拟表的字段
3.逻辑独立性
缺点:
1.性能没有提升,简单表会变得复杂
2.修改不方便,有多种情况不能修改虚拟表的
创建视图:
create view myView as
select employee_id,first_name,last_name,salary from t_employees;
select * from myView;
update myView set salary=30000 where employee_id=100;
修改视图:
方式1:创建或修改
CREATE OR REPLACE VIEW myView AS
select employee_id,first_name,last_name from t_employees;
方式2:修改视图
alter VIEW myView AS
select employee_id,first_name,last_name,salary from t_employees;
删除视图
drop view myView;
视图的不可更改性:
create view myView as
select department_id,count(*) from t_employees group by department_id;
update myView set department_id=119 where department_id=10;
2.综合练习
先导入数据,然后完成下面练习:
1.查询所有用户的订单
select * from user u inner JOIN orders o on u.userid=o.userid;
2.查询用户id为 1 的所有订单详情
select * from user u INNER JOIN orders o on u.userid=o.userid
INNER JOIN orderitem oi on o.oid= oi.oid where u.userid=1;
3.查看用户为张三的订单
select * from orders where userid=(select userid from user where username='张三');
4.查询出订单的价格大于800的所有用户信息。
select * from user where userid in (select DISTINCT userid from orders where totalprice>800);
5.查询所有订单信息,每页显示5条数据
select * from orders limit 0,5; 第一页
select * from orders limit 5,5; 第二页
select * from orders limit 10,5; 第三页
规律:
已知当前页,页大小(每页条数),求起始下标
起始下标= (当前页-1)*页大小
边栏推荐
- 搭建一套 gocd 的环境
- Visual display of TEQC quality analysis results using teqcplot
- Drag and drop frame
- HCIP第五次作业
- [MAC] there is no source option in security and privacy
- 104. 简易聊天室7:使用 Socket 传递对象
- A bug in rtklib2.4.3 B34 single point positioning
- C language stack implementation
- Strong push, quick start to software testing
- Post processing of multisensor data fusion using Px4 ECL
猜你喜欢

vmware网络连接出错Unit network.service not found

Hcip reissue experiment

stm32时钟树错误配置导致 开机进入硬中断

网上有真实的兼职吗?大学生怎么找暑期兼职?

insert into... where not exists插入避免重复的使用

onnxoptimizer、onnxsim使用记录

985 test engineer is hanged. Who is more important in terms of education and experience?

【微服务|Nacos】Nacos实现多环境和多租户的数据隔离

【opencv450】帧间差分法

APP自动化测试-Appium进阶
随机推荐
直接插入排序——【常见排序法(1/8)】
STP summary
关于信息泄露和防御
计算欧式距离和余弦相似度
Sift特征点提取
Missing essential plugin
Introduction and use of precise ephemeris
Architecture à trois niveaux MVC
Post processing of multisensor data fusion using Px4 ECL
The propeller framework v2.3 releases the highly reusable operator library Phi! Restructure development paradigm to reduce cost and increase efficiency
OSPF分流实验
Error related to synchronizing domestic AOSP code
Onnxoptimizer, onnxsim usage records
shutdown关机命令
Mongodb sharding principle
104. 简易聊天室7:使用 Socket 传递对象
Strong push, quick start to software testing
小时候 觉得爸爸就是天 无所不能~
JSP入门级笔记
Calculate Euclidean distance and cosine similarity