2. Data and Databases

Sql Basics — Quiz

Test your understanding of sql basics with 5 practice questions.

Read the lesson first

Practice Questions

Question 1

Consider two tables: $\text{Employees (EmployeeID, Name, Salary, DepartmentID)}$ and $\text{Departments (DepartmentID, DepartmentName)}$. Which SQL query will return the $\text{DepartmentName}$ and the total $\text{Salary}$ for each department, but only for departments where the total $\text{Salary}$ is greater than $\text{100000}$ and the department has more than $\text{5}$ employees?

Question 2

Given a table $\text{Courses (CourseID, CourseName, DepartmentID)}$ and another table $\text{Enrollments (EnrollmentID, StudentID, CourseID, Grade)}$. Which SQL query will return the $\text{CourseName}$ and the average $\text{Grade}$ for each course, but only for courses that have an average $\text{Grade}$ greater than $\text{80}$ and have more than $\text{10}$ students enrolled?

Question 3

Consider a table $\text{Orders (OrderID, CustomerID, OrderDate, OrderTotal)}$ and $\text{Customers (CustomerID, CustomerName)}$. Which SQL query will return the $\text{CustomerName}$ and the total $\text{OrderTotal}$ for each customer, including customers who have not placed any orders, and only for customers whose total $\text{OrderTotal}$ is greater than $\text{500}$?

Question 4

Consider a table $\text{Products (ProductID, ProductName, Category, Price)}$. Which SQL query will return the $\text{Category}$ and the average $\text{Price}$ for each category, but only for categories that have more than $\text{3}$ products and an average $\text{Price}$ greater than $\text{100}$?

Question 5

Given a table $\text{Students (StudentID, StudentName, MajorID)}$ and $\text{Majors (MajorID, MajorName)}$. Which SQL query will return the $\text{MajorName}$ and the number of students in each major, but only for majors that have more than $\text{20}$ students and where the $\text{MajorName}$ starts with 'Computer'?