You are on page 1of 4

Dear All,

The following is our homework this week. Its due date (and time) is Sunday, 15.11.2020, 23:55.

You are encouraged to complete them with your chosen DBMS, using the given COMPANY database
whose DDL statements and data population are provided.

What you will submit is a PDF file that contains your answers after you check them with the database
on the DBMS. Once again, the submitted PDF file must be named with an inclusion of your name and
student identifier.

Should you have any questions, please feel free to contact me asap.

Cheers,

Chau

1
1. Write SELECT statements for the following queries on the COMPANY database and then their
corresponding relational algebra expressions.

1.1. Retrieve the project number and name of each project in Houston.

1.2. Retrieve the project number and name of each project controlled by ‘Administration’ department.

1.3. Retrieve the project number and name of each project in Houston or controlled by ‘Administration’
department.

1.4. Retrieve the project number and name of each project on which more than three employees work.

1.5. Retrieve the project number and name of each project on which more than three employees
including Smith work.

1.6. Retrieve the project number and name of each project on which more than three employees
including Smith but not Borg work.

1.7. Retrieve the project number and name of each project which has the highest number of employees
who work on it.

1.8. Retrieve the project number and name of each project which has a name like ‘Product…’, locates in
Houston and is controlled by the department where English works.

1.9. Retrieve the project number and name of each project on which Smith works or is controlled by the
departments which Smith does not work for.

1.10. Retrieve the project number and name of each project in Houston on which the employees with
salaries higher than $30,000 in ‘Administration’ department work.

1.11. Retrieve the total number of employees and their total hours working on the projects which are in
the same location as their controlling departments.

1.12. Return the average salary, highest salary, and lowest salary of the employees who worked on all
the projects which Smith works on.

1.13. For each department whose average employee salary is more than $30,000, retrieve the
department name and the number of employees working for that department.

1.14. For each department, retrieve the department name and the number of male employees in each
department making more than 30,000.

1.15. Retrieve the names of all employees who work in the department that has the employee with the
highest salary among all employees.

1.16. Retrieve the names of all employees whose supervisor’s supervisor has ‘888665555’ for Ssn.

2
1.17. Retrieve the names of employees who make at least $10,000 more than the employee who is paid
the least in the company.

2. Specify the following VIEWs in SQL on the COMPANY database schema.

2.1. A view that has the department name, manager name, and manager salary for every department.

2.2. A view that has the employee name, supervisor name, and employee salary for each employee who
works in the ‘Research’ department.

2.3. A view that has the project name, controlling department name, number of employees, and total
hours worked per week on the project for each project.

2.4. A view that has the project name, controlling department name, number of employees, and total
hours worked per week on the project for each project with more than one employee working on it.

3. Consider the following view, DEPT_SUMMARY, defined on the COMPANY database. State which of the
following queries and updates would be allowed on the view. If a query or update would be allowed,
show what the corresponding query or update on the base relations would look like, and give its result
when applied to the database on your chosen DBMS.

CREATE VIEW DEPT_SUMMARY (D, C, Total_s, Average_s)

AS SELECT Dno, COUNT (*), SUM (Salary), AVG (Salary)

FROM EMPLOYEE

GROUP BY Dno;

3.1. Query 1

SELECT *

FROM DEPT_SUMMARY;

3.2. Query 2

SELECT D, C

FROM DEPT_SUMMARY

WHERE TOTAL_S > 100000;

3
3.3. Query 3

SELECT D, AVERAGE_S

FROM DEPT_SUMMARY

WHERE C > ( SELECT C FROM DEPT_SUMMARY WHERE D = 4);

3.4. Update

UPDATE DEPT_SUMMARY

SET D = 3

WHERE D = 4;

3.5. Delete

DELETE FROM DEPT_SUMMARY

WHERE C > 4;

You might also like