Lab 4 - CLC
Lab 4 - CLC
Lab 4 SQL
Overview:
What you need to submit is the SQL command;
The logical schema is shown below for your reference, it’s especially helpful when you write multiple
table queries. Note: some of you might have different table name and attribute name.
Employee
FName Minit LName SSN BDate Address Sex Salary SuperSSN DepNo
Department
DName DepNo MgrSSN MgrSDate
Dept_Locations
DepNo DLocation
Project
Works_On
Dependent
Notes:
- SSN is social security number, it means employee’s identification number.
- SuperSSN: each employee may have a supervisor, who is also an employee, to supervise their
works
- Fname, Minit, Lname: first name, middle name and lastname
- DepNo: department number or department id
1 Huynh Ngoc Tu
FACULTY OF INFORMATION TECHNOLOGY
SCHOOL YEAR: 2019 – 2020
SEMESTER II
DATABASE SYSTEMS
- MgrSSN: manager’s SSN; MgrSSN àSSN: because manager is just an employee in this
company, they must have a SSN number which is stored in Employee table.
- MgrSDate: a date to start to be a manager
- ESSN(in Works_On table) is just a SSN, but different name.
- The arrows à here are used to describe the relationship between these tables. Look at them to
create foreign keys.
- Dependent: relation to store family members of an employee.
Standalone Queries
1. List department number, department name, and number of employees in each department, ordered
by number of employees in each department.
2. List departåment number, department name, and number of employees in departments that have
more than 2 employees, ordered by department number.
4. List female employee name and project name and project number that she is working on.
5. List the name of employees who has a dependent of the same gender as the employee.
7. List the name of employees who are not working on any projects.
8. For each department, list department number, number of employees, and average salary.
9. List the name and number of departments whose employee average salary is between 30000 and
60000.
2 Huynh Ngoc Tu
FACULTY OF INFORMATION TECHNOLOGY
SCHOOL YEAR: 2019 – 2020
SEMESTER II
DATABASE SYSTEMS
11. List the name of employees who work on both project 3388 and project 1945.
12. List the department number and project number that are controlled by each department, ordered by
project number.
13. List the total working hours of each employee. Hint: use SUM(hours)
14. List the name of employees whose supervisor does not have a supervisor.
15. List the name of employees who both lives (address) and works (department location) in Salt Lake
City.
16. List the name of supervisors who starts to supervise a department before Sep 20, 1976.
3 Huynh Ngoc Tu