CREATE DATABASE dbtest4 CHARACTER SET 'utf8';
员工号(EMPLOYEE_ID),部门号(DEPARTMENT_ID)
USE dbtest4;
CREATE VIEW employee_vu(lname,emp_id,dept_id)
AS
SELECT last_name,employee_id,department_id
FROM atguigudb.employees;
DESC employee_vu;
SELECT * FROM employee_vu;
CREATE OR REPLACE VIEW employee_vu(lname,emp_id,dept_id)
AS
SELECT last_name,employee_id,department_id
FROM atguigudb.employees
WHERE department_id = 80;
CREATE TABLE empsAS
SELECT * FROM atguigudb.employees;
CREATE OR REPLACE VIEW emp_v1
AS
SELECT last_name,salary,email
FROM atguigudb.employees
WHERE phone_number LIKE '011%';
#的员工姓名和邮箱、电话号码
CREATE OR REPLACE VIEW emp_v1
AS
SELECT last_name,email,phone_number,salary
FROM atguigudb.employees
WHERE phone_number LIKE '011%'
AND email LIKE '%e%';
SELECT * FROM emp_v1;
答:不行 因为在插入的过程中也会往基表中插入数据,且
只插入这三个字段,基表中的其他字段可能有默认非空的 这样导致失败
SELECT * FROM emp_v1;
UPDATE emp_v1
SET salary = salary + 1000;
DELETE FROM emp_v1
WHERE last_name = 'Olsen';
SELECT *
FROM emp_v1
WHERE last_name = 'Olsen';
CREATE OR REPLACE VIEW emp_v2(department_id,max_salary)
AS
SELECT department_id,max(salary)
FROM atguigudb.employees
GROUP BY department_id
HAVING max(salary) > 12000;
SELECT * FROM emp_v2;
答:肯定不行啊
DROP view IF exists emp_v2,emp_v1;
SELECT * FROM emp_v2;
SELECT * FROM emp_v1;