Understand the concept
Name output grain, eligible records and date range. Clarify NULLs, cancellations, ties and zero values. Correct SQL for the wrong metric is still an incorrect answer.
Apply the method
Inspect intermediate results. Count rows before and after joins and check a known customer by hand. For percentages, state the denominator and use decimal division. Do not average group percentages without considering population weights.
Avoid a common mistake
After correctness, discuss maintainability and cost. Indexes may help filters but add write cost. EXPLAIN QUERY PLAN can reveal scans; a tiny dataset cannot establish production performance. These mock tests are self-practice, not employer-verified assessments.
Worked query
Return customer_id and revenue_percent of total paid revenue, rounded to two decimals. Only customers with paid orders; order by customer_id.
WITH t AS(SELECT customer_id,SUM(amount) AS revenue FROM orders WHERE status='paid' GROUP BY customer_id) SELECT customer_id,ROUND(100.0*revenue/SUM(revenue) OVER(),2) AS revenue_percent FROM t ORDER BY customer_id;Run and explore this example →Check your understanding
Before running your query, predict the output columns and approximate row count. After running it, inspect a missing value, a tie and a record with no match when available. Explain why the result answers the question.
Practice this topic
- Customer revenue share — Return customer_id and revenue_percent of total paid revenue, rounded to two decimals. Only customers with paid orders; order by customer_id.
- Detect salary ties — Return salary and employees (count) for known salaries shared by multiple employees, ordered by salary.
- Month-over-month change — Return month and revenue_change versus prior month of paid revenue; first month NULL. Order by month.
- Customer lifecycle report — Return name,paid_orders,last_paid_date for every customer, including zero and NULL. Order by customer id.
- Unpaid-only customers — Return name for customers with orders but never a paid order, ordered by customer id.
- January signup returners — Return returning_users: distinct January signup users with a February 2026 login.
- Low-stock exposure — Return category and stock_value (sum price times stock) for products with stock <=5, ordered by category.
- Gap to department maximum — Return name and gap_to_max (department maximum minus salary), preserve NULL. Order by id.
- Days between orders — Return id and days_since_previous as integer days since previous customer order, first NULL. Order output by id.
- Signup to purchase — Return signup_users and purchasing_signup_users as distinct signup users and those with any purchase.
SQLite reference: SQL language documentation. Written by Future Data Academy with AI assistance; query examples checked against the supplied teaching dataset.
