SQL Level 2 Test
This test checks Level 2 of the course, Intermediate: the intermediate lessons: keys, joins, subqueries, functions, views, indexes and transactions. It has two parts. The 15 questions test that you know what each feature does; the 5 hands-on tasks test that you can use it, the way real work does: you run your own SQL in Try it and compare it with the solution. If you pass, you're ready for the next level; if you don't, every question links to the lesson that explains it.
How the Test Works
- Part 1: 15 multiple-choice questions, marked for you.
- Part 2: 5 tasks of these kinds: Predict, Write and Fix. Write your query, run it, then open the solution and compare the rows. Any query that returns the same rows passes; the order matters only when the task asks for one.
- Pass mark: 15 out of 20 (questions plus tasks). Give yourself one point per task whose result matches.
- Time: about 45 minutes. No notes for Part 1; Part 2 is open-book, as real work is.
- Covers: the lessons from Constraints to Transactions. Some tasks use the shop dataset, an online store with 5,000 customers and 60,000 orders; Try it loads it the first time you run one of those tasks, which takes a few seconds.
Part 1: 15 Questions
Part 2: 5 Hands-On Tasks
Task 1 (Predict): A LEFT JOIN with a filter. Predict the rows, then run it: SELECT s.first_name, p.amount_usd FROM students s LEFT JOIN payments p ON p.student_id = s.student_id AND p.amount_usd > 400 ORDER BY s.first_name;
Show solution
SELECT s.first_name, p.amount_usd
FROM students s
LEFT JOIN payments p ON p.student_id = s.student_id AND p.amount_usd > 400
ORDER BY s.first_name, p.amount_usd; first_name | amount_usd
------------+------------
Advitha | NULL
Navika | NULL
Srihitha | 450.00
Srihitha | 550.00
(4 rows)Task 2 (Fix): The doubled total. This query should give each student's total paid, but Srihitha's total is too big. Find and fix the bug: SELECT s.first_name, sum(p.amount_usd) FROM students s JOIN enrollments e ON e.student_id = s.student_id JOIN payments p ON p.student_id = s.student_id GROUP BY s.first_name;
Show solution
-- Joining enrollments multiplied each payment by the student's number of
-- enrollments. Payments already carry student_id, so drop that join.
SELECT s.first_name, sum(p.amount_usd) AS total_paid_usd
FROM students s
JOIN payments p ON p.student_id = s.student_id
GROUP BY s.first_name
ORDER BY s.first_name; first_name | total_paid_usd
------------+----------------
Navika | 450.00
Srihitha | 1700.00
(2 rows)Task 3 (Write): Unpaid enrollments. List each active enrollment (student first name, course title) with no payment at all for that course.
Show solution
SELECT s.first_name, c.title
FROM enrollments e
JOIN students s ON s.student_id = e.student_id
JOIN courses c ON c.course_id = e.course_id
WHERE e.status = 'active'
AND NOT EXISTS (SELECT 1 FROM payments p
WHERE p.student_id = e.student_id AND p.course_id = e.course_id)
ORDER BY s.first_name, c.title; first_name | title
------------+-------------
Advitha | Java Basics
Advitha | SQL Basics
(2 rows)Task 4 (Write (shop)): Orders per state. On the shop dataset, count delivered orders per customer state in 2025, top five states.
Show solution
SELECT c.state, count(*) AS delivered_orders
FROM orders o
JOIN customers c ON c.customer_id = o.customer_id
WHERE o.status = 'delivered'
AND o.ordered_on >= '2025-01-01' AND o.ordered_on < '2026-01-01'
GROUP BY c.state
ORDER BY delivered_orders DESC, c.state
LIMIT 5; state | delivered_orders
-------+------------------
IL | 2372
GA | 2370
CO | 2354
NY | 2354
FL | 2352
(5 rows)Task 5 (Write (shop)): Never ordered. On the shop dataset, which products have never been ordered? Show the product name and category.
Show solution
SELECT p.name, p.category
FROM products p
WHERE NOT EXISTS (SELECT 1 FROM order_items i WHERE i.product_id = p.product_id)
ORDER BY p.name; name | category
------------------------+----------
Database Design Course | courses
Design Patterns Course | courses
(2 rows)What Your Score Means
| Score | What to do |
|---|---|
| 18 to 20 | Excellent. Move on to the SQL Level 3 Test when you reach it. |
| 15 to 17 | A pass. Reread the lessons linked from the questions you missed. |
| Below 15 | Not yet. Revise the linked lessons and take the test again in a day or two. |
Was this tutorial helpful?