DB - Labtest1 - Sem 1 - 2024 - 25 - UN1 - Monday
DB - Labtest1 - Sem 1 - 2024 - 25 - UN1 - Monday
Lab Test #1
DATE: November 18, 2024 DURATION: 3 HOURS
Scenario:
Promaneng Company Ltd is an engineering company that works on various engineering projects across the
island. They employ various person such as engineers, welders, masons, plumbers etc. to work on these
projects. Employees may be working on several projects simultaneously. However, whenever an employee is
assigned to a project, their work as to be signed off and audited by a senior employee who is the Foreman. The
company wants to track the date an employee was assigned to a project, the rate paid and date their
assignment is ended. Each project will have a name, the client who owns the project, estimated cost, estimated
time of completion, a code and location. Each employee possesses several skills in addition to their personal
details. Your job is to implement the database. The relational schema is given below:
Employee (EmpID, fName, lName, mName, address, position, email, dob, gender, employDate)
EmpSkills (EmpID, skill)
Foreign Key EmpID references Employee
Project (prjCode, location, prjEstimate, client, EstimatedDuration, prjCost, dateCompleted)
ProjectAssignment(EmpID, prjCode, rateperHr, dateAssigned, noOfDaysWorked, Foreman)
Foreign Key EmpID references Employee
Foreign Key prjCode references Project
Foreign Key Foreman references Employee
1
.
Table 2: Employee information
empID Name skills EmpDate Gender Address & phone DOB Position
mm/dd/yy
1071 Kyon Brown Design, project 10/12/1999 M 12 Parkview Lane, Porous, 09/20/1970 engineer
management Manchester
876-983-2211
2345 Jugga Welding, masonry 04/28/2014 M 13 Rose Ave, May Pen, 01/31/1985 welder
Blacks Clarendon
876-955-9003
3227 Arya Stark Welding, masonry 09/27/2021 F 2 Cow Market, Spanish Town 11/22/2000 Crane
St. Catherine operator
876-984-9978
4129 Seong Lang Masonry, 08/21/2015 F Ocean Boulevard, Kingston 09/10/1992 helper
plumbing 876-487-1923
6578 Nigel designing 12/15/2001 M 12 Broadway, Manor Park, St. 12/4/1960 engineer
Podrick Andrew
876-554-0017
8762 Dee Syde Masonry, painting, 01/27/2022 F 3 Burke Rd, Spanish Town, 09/27/1984 helper
plumbing St. Catherine
Employee Client Supervised By Date Assigned Rate per hour Date Ended
for each emp. $
Frodo, Dee Syde Petro_Oil Co. Ltd Nigel Podrick 1/15/2024 750 & 650 7/13/2024
Jugga, Seong Petro Oil Co. Ltd Kyon Brown 8/2/2023 550, 1100 & 10/8/2024
Lang, Arya 1050
Jugga, Arya Superfed Co Ltd Kyon Brown 6/1/2022 $540 & $550
Task 2 -Demonstrate interacting with data with one SQL statement (22 marks)
a. Develop appropriate full and partial insert statements for each table [8]
(Information in Tables 1 and 2 should be inserted as well as other information given)
b. Arya Stark worked on National Power Company’s project for only 26 days. Use a function to
calculate and update the date she ended her work assignment for that project.
[4]
c. There will be a special recognition ceremony in seven (7) months time for all employees who
have been with the company for at least 2 years at the time of the ceremony and for employees
who will reach retirement age at the time of the ceremony (60 years). Display the names, gender,
email and number of years of employment at the time of the Ceremony, age at time of the
ceremony for these employees. Sort the results by month of employment in ascending order
male employees first.
[5]
d. Display the client, date began, date ended, estimated duration, actual duration in months, number
of days overrun (assume 30 day months) for all projects where the project lasts longer than
expected or for those clients that is not a limited liability company (ltd).
[5]
a. Display the client, project location, date project began, duration of project in days, estimated cost,
employees with skills in welding or masonry that is assigned to the project showing date assigned
to the project, their gender, position and address and the name of the employee who is overseeing
the work on the project.
[8 marks]
3
b. Using a left join display the employees that have not been assigned to work on any project. Show
their full name (as one string), age, skills, gender and phone number. Sort the records by age,
female employees first.
[5]
c. Using a right join display all projects that has no employees assigned to work on it.
[5]
d. Using sub-queries and join statements, for projects that were completed (project has ended) within
the estimated time, we want to know the client, the value of the project, the employee that
supervised the other employees that worked on the project (full name, position, years of
employment) and the actual duration of the project.
[6]
e. Show the employee that was the first to join the company. Show their name, gender, years of
employment, date joined, dob, age and their skills. Ensure at least one sub-query and one IN
statement is included in your solution.
[6]
f. Create a view that shows each employee name, rate per hour, gender, Potential earnings (based on
a 40 hr work week), date of birth, age, number of years of employment for all employees assigned
to work on projects. The potential earnings are based on their duration on a project to date.
Assume a 30 day for each month and weekends not included.
[7]
Task 4: Aggregate Functions (18 marks) – Use one statement for each task
a. Calculate the average months of employment of male and female employees (Use one statement)
[4]
b. Display the total estimated cost for all projects by location having a value in excess of a
9 million dollars.
[4]
c. How many employees are supervising projects that are still ongoing?
[3]
d. Display the name, phone number and age of the youngest female employee?
[4]
e. Display duration in days of the project that took the most days to complete to date.
[3]