Disclaimer: The problems are taken from a mock exam provided by the course. I do not take credit for them.
KCL Module Ref.: 7CCSMDDW.
Q1. Given the relation
is the functional dependency
Solution: The answer is YES. We can see that
(The first step is given by the splitting rule. The second step is respectively given by the axiom of augmentation and transitivity).
We are given the following database schema:
employee(empid, lname, location, salary, manager)project(projectID, projectName, projectLeader, budget)projectemployees(contractID, empID(FK), projectID(FK), contract_length)
Q2. List the last name of the employees based in London who have the lowest salary. Note that more than one employee might have the lowest salary if they have the same salary.
Solution:
SELECT lname FROM employee WHERE salary = ( SELECT MIN(salary) FROM employee WHERE location = "London" );
Q3. Which employees are working on the most projects?
Solution:
SELECT empID, COUNT(projectID) AS NumberOfProjects FROM projectemployees GROUP BY empID HAVING COUNT(projectID) = ( SELECT MAX(P) FROM ( SELECT empID, COUNT(projectID) AS P FROM projectemployees GROUP BY empID ) );
We could also make it better by performing an inner join with the employee table to access more information about the employee:
SELECT employees.empID, employees.lname, employees.fname, COUNT(projectemployees.projectID) AS NumberOfProjects FROM projectemployees INNER JOIN employees ON projectemployees.empID = employees.empID GROUP BY projectemployees.empID HAVING COUNT(projectemployees.projectID) = ( SELECT MAX(P) FROM ( SELECT empID, COUNT(projectID) AS P FROM projectemployees GROUP BY empID ) );