#本章关键字:
VIEW (视图关键字)
# 视图
# 作用:可以使复杂的查询变得简单# 创建: VIEW(关键字) emp_v_10(视图名字)
# 简单视图创建
CREATE VIEW emp_v_10 AS
SELECT EMPNO AS 部门名称, ename 员工姓名, sal 工资
FROM tb_emp
WHERE deptno = 10;
#使用视图
SELECT * FROM emp_v_10;
#复杂视图创建
CREATE VIEW emp_v AS
SELECT deptno AS 部门名称,AVG(sal) AS 平均工资,MAX(sal) AS 最高工资,
MIN(sal) AS 最低工资,SUM(sal) AS 工资总数,COUNT(1) AS 部门人员
FROM tb_emp
GROUP BY deptno
SELECT * FROM emp_v;