Test what you have learned in this SQL tutorial. Each question has one correct answer. If you get stuck, the SQL Keyword Reference has a summary of every keyword, with links back to the lessons.
Before you start, here is one last warm-up query that pulls together joins, grouping, HAVING, sorting and LIMIT: the top three customers by total value of delivered orders.
Example SQL
SELECT c.name,
SUM(oi.quantity * p.price) AS delivered_value
FROM customers AS c
JOIN orders AS o ON o.customer_id = c.customer_id
JOIN order_items AS oi ON oi.order_id = o.order_id
JOIN products AS p ON p.product_id = oi.product_id
WHERE o.status = 'delivered'
GROUP BY c.customer_id, c.name
HAVING SUM(oi.quantity * p.price) > 10000
ORDER BY delivered_value DESC
LIMIT 3;Try it Yourself »And a second one combining a subquery with CASE: every product with how many units have been ordered and a simple sales label.
Example SQL
SELECT p.name,
COALESCE((SELECT SUM(oi.quantity) FROM order_items AS oi
WHERE oi.product_id = p.product_id), 0) AS units_ordered,
CASE
WHEN (SELECT SUM(oi.quantity) FROM order_items AS oi
WHERE oi.product_id = p.product_id) >= 5 THEN 'Best seller'
ELSE 'Steady'
END AS label
FROM products AS p
ORDER BY units_ordered DESC;Try it Yourself »If you can read both of these and explain what each line does, you are in good shape. Now for the quiz.
Tip: Missed a question? Go back to the lesson, open the Try it Yourself editor and experiment with the Skope Shop database until the idea clicks. Practice is the fastest way to learn SQL.
SKOPE