视图可能非常复杂query(aggregations, joins, subqueries, etc)。只需确保为选择的所有内容添加列名即可:
Create VIEW dept_income AS SELECTd.Nameas DepartmentName, sum(e.salary) as TotalSalary FROM Employees e JOIN Departments d one.DepartmentId= d.id GROUP BY d.Name;
现在,您可以从任何表格中进行选择:
SELECT * FROM dept_income;
部门名称 | 工资总额 |
---|---|
人力资源 | 1900年 |
营业额 | 600 |