Course Resources

Search

Search IconIcon to open search

Last updated Nov 17, 2024

The format and topics covered in this practice final closely mirror what you will encounter on the final exam. To ensure you’re fully prepared, these practice questions are designed to be slightly more challenging versions of the types of questions you’ll be asked in the final exam.

# SDEV 201 Practice Exam

# Part 1: Querying

Given the following tables, write SQL queries to retrieve the requested information.

# Employee
EmployeeIDFirstNameLastNameDepartmentIDSalary
1AhmedKhan165,000
2SamanthaDavis280,000
3AvaWilliams372,000
4DiegoGonzalez290,000
5SamJohnson468,000
6SamirPatel375,000
# Project
ProjectIDNameDepartmentIDBudget
1Website Redesign250,000
2Recruitment Drive125,000
3Financial Analysis340,000
4Marketing Campaign460,000
5Server Upgrade235,000
# Department
DepartmentIDName
1HR
2IT
3Finance
4Marketing
# ProjectAssignment
AssignmentIDEmployeeIDProjectIDHoursWorked
11240
22135
32525
43345
54150
64530
75455
86340
  1. Write a query to retrieve the ID, first name, and last name of all employees.
Show Answer SELECT EmployeeID, FirstName, LastName FROM Employee;
  1. Write a query to retrieve the project name and budget for all projects in the ‘IT’ department.
Show Answer

SELECT Project.Name, Budget FROM Project

JOIN Department ON Project.DepartmentID = Department.DepartmentID

WHERE Department.Name = 'IT';

  1. What data would be returned by the following query? Fill in the table with the correct information. You may leave the extra rows blank.
1
2
3
4
SELECT FirstName, Salary, Name AS "DepartmentName" FROM Employee
JOIN Department ON Employee.DepartmentID = Department.DepartmentID
WHERE FirstName LIKE '%Sam%' AND Salary > 70000
ORDER BY Salary DESC;
FirstNameSalaryDepartmentName
Show Answer

FirstName | Salary | DepartmentName

Samantha | 80,000 | IT

Samir | 75,000 | Finance

  1. Write a query to retrieve all project assignments. Include the name of the project and the first and last name of the employee. Order the results alphabetically by the project name.
Show Answer

SELECT Name AS ProjectName, FirstName, LastName FROM ProjectAssignment

JOIN Project ON ProjectAssignment.ProjectID = Project.ProjectID

JOIN Employee ON ProjectAssignment.EmployeeID = Employee.EmployeeID

ORDER BY Project.Name ASC;

  1. Write a query to retrieve the employee ID, employee last name and the total hours worked on all projects for each employee. Order the results by the total hours worked (highest to lowest).
Show Answer

SELECT Employee.EmployeeID, LastName, SUM(HoursWorked) AS TotalHours FROM ProjectAssignment

JOIN Employee ON ProjectAssignment.EmployeeID = Employee.EmployeeID

JOIN Project ON ProjectAssignment.ProjectID = Project.ProjectID

GROUP BY Employee.EmployeeID

ORDER BY TotalHours DESC;

# Part 2: Entity Relationship Diagrams and Creating Tables

  1. Draw the Entity Relationship Diagram for the Employee, Project, Department, and ProjectAssignment tables given above. Make sure to include all columns, the data type you think each column should have and any relationships between the tables. Represent relationships between tables with Crow’s Foot Notation.
Show Answer
  1. Write the CREATE statement for only the Project table. Make sure to include all columns, the data type of each column, and any primary or foreign key constraints.
Show Answer

CREATE TABLE Project (

 ProjectID INT PRIMARY KEY,

 Name VARCHAR(100) NOT NULL,

 DepartmentID INT NULL,

 Budget INT NOT NULL,

 FOREIGN KEY (DepartmentID) REFERENCES Department(DepartmentID)

);

Note: Assign columns to be NULL or NOT NULL according to your best judgement.

  1. Based on the Northwind Traders diagram below, write a query to retrieve all orders. Include the order’s ID, the order’s date, the name of the customer who placed the order, and the name of shipper delivering the order.
Show Answer

SELECT OrderID, OrderDate, CustomerName, ShipperName FROM Orders

JOIN Customers ON Orders.CustomerID = Customers.CustomerID

JOIN Shippers ON Orders.ShipperID = Shipper.ShipperID

# Part 3: SQL for Data Analytics

This section is worth only a few points on the final exam. Focus your efforts on parts 1 and 2 before tackling the data analytics section.

Northwind Traders wants to identify the most promising locations for expansion based on current customer purchasing patterns.

Using the Northwind Traders diagram above, construct a query that gives meaningful insights into customer purchasing behavior across different locations to inform the company’s regional expansion decisions. Include at least two calculated or aggregated metrics in your query. Make your the query output is well organized and formatted so it is easy for business stakeholders to understand. Provide a brief explanation of how the query you wrote could inform the expansion strategy.


# Part 3 Answer:

I have no specific answer I have in mind for data analytics questions. I’m looking for functional queries that meet the requirements given in the question and help give meaningful insight into the data. I’m also looking for good reasoning about the kind of conclusions your query can provide and what considerations or assumptions went in to designing your query. Below is one possible solution.

1
2
3
4
5
6
SELECT c.Country, COUNT(*) AS TotalOrders, SUM(od.Quantity * p.Price) AS TotalRevenue FROM Customers c
JOIN Orders o ON c.CustomerID = o.CustomerID
JOIN OrderDetails od ON o.OrderID = od.OrderID
JOIN Products p ON od.ProductID = p.ProductID
GROUP BY c.Country
ORDER BY TotalRevenue DESC;

This query provides an overview of the total orders and revenue generated from each country that Northwind Traders can use to identify their top performing locations. Looking at both total orders and revenue by region is important because it provides a more comprehensive view of market performance and potential.

Total orders can indicate the size of size customer base in each region, while revenue reflects the monetary value of those orders. A region with many orders but low revenue may have a large but low-spending customer base, while a region with few orders but high revenue may have a smaller but high-value customer base.