|
select fname, lname, dname, salary
from employee, department
where dno=dnumber
Output:
+--------+---------+----------------+----------+
| fname | lname | dname | salary |
+--------+---------+----------------+----------+
| John | Smith | Research | 30000.00 |
| Frankl | Wong | Research | 40000.00 |
| Alicia | Zelaya | Administration | 25000.00 |
| Jennif | Wallace | Administration | 43000.00 |
| Ramesh | Narayan | Research | 38000.00 |
| Joyce | English | Research | 25000.00 |
| Ahmad | Jabbar | Administration | 25000.00 |
| James | Borg | Headquarters | 55000.00 |
+--------+---------+----------------+----------+
|
Notice that:
|
Example:
CREATE VIEW DeptEmps
AS
(
select fname, lname, dname, salary
from employee, department
where dno=dnumber
)
|
Example:
select * from DeptEmps
Output:
+--------+---------+----------------+----------+
| fname | lname | dname | salary |
+--------+---------+----------------+----------+
| John | Smith | Research | 30000.00 |
| Frankl | Wong | Research | 40000.00 |
| Alicia | Zelaya | Administration | 25000.00 |
| Jennif | Wallace | Administration | 43000.00 |
| Ramesh | Narayan | Research | 38000.00 |
| Joyce | English | Research | 25000.00 |
| Ahmad | Jabbar | Administration | 25000.00 |
| James | Borg | Headquarters | 55000.00 |
+--------+---------+----------------+----------+
|
CREATE VIEW Dept_Info(dname, no_emps, total_sal)
AS
( SELECT dname, count(ssn), sum(salary)
FROM department, employee
WHERE dnumber = dno
GROUP BY dname
)
|
|
Solution:
SELECT *
FROM Dept_Info
WHERE no_emps > 2
DNAME NO_EMPS TOTAL_SAL
--------------- ---------- ----------
Administration 3 93000
Research 4 133000
|
UPDATE employee SET salary = salary + 10000 |
Notice that the salary value changed in the view also
(So the sum is computed using the updated salary values !!!)