--视图: 是介于表和结果集之间的一个虚拟表 ,修改..视图不影响原表结构和数据
--视图如何创建 create or replace view 视图名 as select语句 [with read only];
select * from emp where deptno =30;
create or replace view vw_haha as (select * from emp where deptno =30);
--视图的优点: 1.使用更简单 2.封装 3.隐藏
--视图如何使用
select * from vw_haha where empno=7654;
--视图如何删除 drop view 视图名;
drop view vw_haha;
--查询部门经理人平均薪资最低的部门名称
--找出所有经理人
select distinct mgr from emp where mgr is not null;
--每个部门经理人的平均薪资
select avg(sal) svg_sal , deptno
from emp
where empno in (select distinct mgr from emp where mgr is not null)
group by deptno;
--最低平均薪资
select min(avg(sal))
from emp
where empno in (select distinct mgr from emp where mgr is not null)
group by deptno;
--找到每个部门经理人的平均薪资等于最低平底平均薪资的部门编号
select deptno from (select avg(sal) avg_sal , deptno
from emp
where empno in (select distinct mgr from emp where mgr is not null)
group by deptno) where avg_sal=(select min(avg(sal))
from emp
where empno in (select distinct mgr f
数据库09笔记(视图和索引)
最新推荐文章于 2024-05-23 19:52:15 发布
本文详细探讨了数据库中的视图概念,包括其创建、使用及优缺点。同时,深入解析了索引的工作原理,如何提高查询效率,并讨论了不同类型的索引及其适用场景。通过对这两个关键概念的理解,读者将能更好地优化数据库性能。
摘要由CSDN通过智能技术生成