Exercise SQL
Exercise SQL
Exercise
This exercise has 3 parts, each part made up of multiple questions. You should read through
the exercise quickly and plan your time-management accordingly.
Good luck!
Part 1
The relational database schema below is part of a company database schema. The 6 tables
describe employees, departments, buildings, which department an employee works in,
department managers, and in which building an employee works. The primary key of each
table is the attribute(s) with an underline mark. Foreign keys are marked in bold.
Employee
EmployeeId EmployeeName Salary Start_Date
Building
BuildingId BuildingName Address
Department
DepartmentId DepartmentName Budget
EmpInDept
EmployeeId DepartmentId
EmpInBld
EmployeeId BuildingId
MngDept
EmployeeId DepartmentId
1. Based on the structure of the tables and your knowledge on Relational Databases,
which of the following statements are correct (Mark as many as are correct)
a. A department can have more than one manager
b. An employee may have more than one office in different buildings
c. An employee can manage only one department
d. A department can reside in only one building
Page 1 of 7
2. Which of the following queries finds the names of buildings in which more than 50
employees work? (Mark as many as are correct)
a. SELECT BuildingName
FROM Building
WHERE BuildingId IN (SELECT BuildingId
FROM EmpInBld
GROUP BY BuildingId
HAVING Count(*) > 50)
b. SELECT BuildingName
FROM EmpInBld
GROUP_BY BuildingId
WHERE Count(*) > 50
c. SELECT BuildingName
FROM Building B
WHERE 50 < (SELECT Count(*)
FROM EmpInBld EIB
WHERE EIB. BuildingId = B. BuildingId)
d. SELECT BuildingName
FROM Building B, EmpInBld EIB
WHERE B.BuildingId = EIB.BuildingId
GROUP BY B. BuildingId
HAVING Count(*) > 50
Page 2 of 7
3. Which of the following queries finds the name of the Department(s) where the
highest paid employee works? (Mark as many as are correct)
a. SELECT D.DepartmentName
FROM Department D
WHERE D.DepartmentId IN (SELECT T.DepartmentId, MAX(Salary)
FROM Department T, EmpInDept EID, Employee E
WHERE T.DepartmentId = EID.DepartmentId and
E.EmployeeId = EID.EmployeeId)
b. SELECT DepartmentName
FROM Department
WHERE DepartmentId IN (SELECT EID.DepartmentId
FROM EmpInDept EID, Employee E
WHERE EID.EmployeeId = E. EmployeeId AND
E.Salary = (SELECT MAX(Salary)
FROM Employee))
c. SELECT DepartmentName
FROM Department D, EmpInDept EID, Employee E
WHERE D. DepartmentId = EID.DepartmentId and E. EmployeeId =
EID.EmployeeId and E.Salary >= ALL (SELECT Salary
FROM Employee)
d. SELECT DepartmentName
FROM Department D, EmpInDept EID, Employee E
WHERE D. DepartmentId = EID.DepartmentId and E.EmployeeId =
EID.EmployeeId and E.Salary = MAX(Salary)
Page 3 of 7
Part 2
The relational database schema below is a part of a University database schema. The tables
describe students, departments, faculty, courses, when each course for given, who is the
faculty that taught each course and enrollment of students to courses.
Student
studentId firstName lastName deptNo
Department
deptNo deptName mngId
Faculty
empId firstName lastName deptNo
Course
courseNo courseName credit deptNo
CourseGiven
courseNo year semester
Teaches
empId courseNo year semester
Enroll
empId courseNo year semester grade
Write the following SQL queries on the university database given above. Write your answers
in the spaces provided.
a. Find the students which finished the “Database” course with a grade higher than 90.
Retrieve their student Id, name (first and last), the department name to which they
belong and their grade in this course.
Page 4 of 7
b. Retrieve the courses number of courses which are offered by the Geography
department which were not given in the fall semester of 2018.
c. Find the students with an average grade in all courses taken is at least 95. Retrieve
their name (first and last), the department to which they belong and the average
grade. Present the results in a descending order of the average grade.
d. Table Course has another column – isActive, which holds the value ‘true’ if the
course is given in the current semester. Else, the value is ‘false’. Write an Update
query to populate this field for semester fall 2018.
Page 5 of 7
Part 3
Below are three cases where a customer opens a support ticket, reporting an issue in the
Gameffective platform. For each case, please write a response to the ticket, based on the
information provided to you in the case description.
Case 1
An admin created a ticket and is reporting a problem that one of their uses cannot log in to
the platform. After initial investigation, you found that the user’s account was locked after
trying to log in to the platform unsuccessfully three times. In order to solve the problem, the
admin simply needs to go in to the Gameffective administration console and unlock the user
account. In the Knowledge Base, you know that there is a “how-to” article that explains
locking/unlocking user accounts.
Case 2
Customer created a ticket complaining that they were trying to load information into the
Gameffective platform through an API, but the API call was failing. After initial investigation,
you asked them to provide what they were trying to send over. When you look at this
information, you notice that they are not providing a field that is mandatory in the API. From
previous engagement with this customer, you know that their IT department is responsible
for the integration with the Gameffective platform and should be handling these kinds of
issues.
Page 6 of 7
Case 3
Admin was trying to create new users on the Gameffective platform and reported that the
operation failed, and an unclear error message appeared on the screen. The admin claimed
that due to this problem, they are totally blocked and cannot continue their work with the
platform.
After investigating the issue with dev team, it turns out that a recent enhancement that was
introduced in another part of the platform had an impact on user creation. The dev team has
provided a rough estimation that they might be able to provide a fix within the next 48
hours.
Page 7 of 7