2. Designing Tables & Combining Data
Practice Lab: Real SQL Query Drills
Practice writing SELECT, WHERE, IS NULL, LEFT JOIN, GROUP BY, HAVING, CASE WHEN, and Window Functions against a live relational database in your browser.
- Write filtered SELECT queries with sorting and NULL checks
- Combine multiple tables with LEFT JOIN to find unmatched rows
- Calculate grouped revenue, HAVING filters, and window rankings on live data
Every SQL playground below runs on a real SQLite engine with pre-loaded tables: courses, students, enrollments, customers, products, orders, and order_items.
Write your query inside each editor, click Run Code, and compare with the sample solution!
Filter raw rows first with WHERE, aggregate with GROUP BY, filter finished groups with HAVING, and finally sort with ORDER BY.
Drill 1: Students Missing a Phone Number
Query students (id, full_name, email) to find only students whose phone is missing (NULL), sorted alphabetically by full_name.
Click “Run Code” to execute this snippet right in your browser.
Drill 2: Customers Who Have Never Ordered
Use customers (id, name, city) and LEFT JOIN orders to list every customer who has 0 orders (o.id IS NULL).
Click “Run Code” to execute this snippet right in your browser.
Drill 3: Paid Revenue Per Product Category
Join products, order_items, and orders (WHERE o.status = 'paid') to calculate total units sold and revenue (SUM(oi.quantity * oi.unit_price)) grouped by p.category.
Click “Run Code” to execute this snippet right in your browser.
Drill 4: High-Value Customers (GROUP BY + HAVING)
Find only customers whose total paid order spend is strictly greater than $100. Remember: WHERE filters orders to 'paid' before grouping, while HAVING filters each customer's total after grouping!
Click “Run Code” to execute this snippet right in your browser.
Drill 5: Label Products by Tier (CASE WHEN)
Classify every row in products as 'Premium' (price >= 50) or 'Standard' (price < 50) using CASE WHEN.
Click “Run Code” to execute this snippet right in your browser.