复杂的观点

视图可以是非常复杂的查询(聚合,连接,子查询等)。只需确保为所选内容添加列名:

Create VIEW dept_income AS
SELECT d.Name as DepartmentName, sum(e.salary) as TotalSalary
FROM Employees e
JOIN Departments d on e.DepartmentId = d.id
GROUP BY d.Name;

现在你可以从任何表中选择它:

SELECT * 
FROM dept_income;
部门名称 TotalSalary
HR 1900
销售 600