Essential storage keeps sign-in and learning features working. Google Analytics measures visits; Microsoft Clarity records interactions to help us improve usability. Both are optional and stay off until you choose. Read our privacy policy.
Work through focused SQL exercises from approachable foundations to more demanding problem-solving patterns.
Start with one core idea at a time and make the basic moves feel automatic.
A learning platform needs an accurate report of published workshops that students can still book. Complete the final SELECT so the report returns each workshop ID, title, level, and calculated remaining_seats. Exclude drafts and full workshops, then sort the smallest availability first and use the title to make ties deterministic.
Support needs a contact list that never shows a blank phone. Return every customer with display_name and a phone_label. When phone is NULL, the label must be the text unlisted. Keep row order by customer_id.
The login form already validated that an email was typed. Complete the SELECT so it returns only that customer's id, email, and display name. Do not return every customer, and do not invent extra columns.
The clerk dashboard shows a short recent-orders strip. Return order_id, customer_id, and placed_on for the two newest orders. Break ties with the larger order_id first so the page is stable.
Combine concepts, validate inputs, and make practical design decisions.
Build Ada's receipt for order 1. Join customers, orders, order_lines, and products so each line shows display_name, order_id, sku, product name, qty, and line_cents (qty times unit_cents). Keep only order 1.
A receiving scan may insert a new sku or add to stock if the sku already exists. Apply one INSERT ... ON CONFLICT so PEN-2 gains 5 units and INK-4 is created at 5. Then return every sku and stock ordered by sku.
Operations wants units sold and revenue per sku, but only for products that sold at least two units. Return sku, units_sold, and revenue_cents. Sort by units_sold descending, then sku.
Work with edge cases, maintainability, and the tradeoffs found in production code.
Create an operations report that keeps every department—even departments with no courses—while counting its published courses and active enrollments. The joins must not inflate the course count, unpublished courses and cancelled enrollments must not contribute, and the final rows must be ordered by active demand.
Attach an AFTER INSERT trigger on order_lines that subtracts NEW.qty from products.stock. Then insert order 3 for Ada buying one MUG-9 at 900 cents, and return mug stock plus the new line. Do not replay the trigger on the historical PEN-2 line: create the trigger after the seed.
Return to the free lessons, editable examples, and quick checks whenever an exercise exposes a gap.
Return every customer with spent_cents and spend_rank. spent_cents is the sum of qty * unit_cents across their lines, or 0 if they never ordered. Rank by spent_cents descending using RANK() so ties share a rank. Order the result by spend_rank, then display_name.