SQL Level 2 Test

Updated · 7 min read
mediumPostgreSQL 18sqltestquizassessmentlevel-2

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

Level 2 test: 15 questions

15 questions
1A foreign key on payments.student_id makes sure that:
2An INNER JOIN between students and payments returns Advitha, who has no payments?
3Which finds courses with no enrollments?
4A CROSS JOIN of 3 students and 6 courses returns:
5A correlated subquery:
6COALESCE(email, phone, 'none') returns:
7CAST('2025-12-03' AS DATE) + 30 is:
8A CASE expression with no ELSE and no matching WHEN returns:
9A view:
10An index on payments (student_id) mainly speeds up:
11Inside a transaction, the second of two UPDATEs fails and you ROLLBACK. What stays changed?
12INSERT ... ON CONFLICT (email) DO UPDATE is:
13UNION and UNION ALL differ in that:
14WHERE fee_usd > ALL (SELECT fee_usd FROM courses WHERE technology = 'Java') keeps courses that cost more than:
15length('Navika') returns:

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
SQL▶ Try 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, p.amount_usd;
Output
 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
SQL▶ Try it
-- 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;
Output
 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
SQL▶ Try it
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;
Output
 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
SQL▶ Try it
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;
Output
 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
SQL▶ Try it
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;
Output
          name          | category
------------------------+----------
 Database Design Course | courses
 Design Patterns Course | courses
(2 rows)

What Your Score Means

ScoreWhat to do
18 to 20Excellent. Move on to the SQL Level 3 Test when you reach it.
15 to 17A pass. Reread the lessons linked from the questions you missed.
Below 15Not yet. Revise the linked lessons and take the test again in a day or two.

Was this tutorial helpful?