複雜的觀點
檢視可以是非常複雜的查詢(聚合,連線,子查詢等)。只需確保為所選內容新增列名:
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 |