
Download the student lab ZIP from this lecture's resources, extract the whole folder and open SQL_Ecommerce_Lab.html in a desktop browser. You'll run your first query, inspect the orders table and see how Run SQL and Check result work. If SQL is new to you, also extract SQL_Lab_Warmup.zip and open its HTML guide. Use Run SQL for the warm-up examples, then use Check result when you return to the numbered cases.
Lab case 01. Count completed orders for January using an inclusive start date and an exclusive end date. Write the query yourself before you watch the answer.
Lab case 02. Join orders to their item lines and sum quantity × unit price to get January merchandise revenue. You'll reuse this total in the final report.
Lab case 03. A WHERE filter quietly turns a LEFT JOIN into an inner join. Move the filters into the join condition so customers with zero orders stay in the result.
Workshop for case 03. Step through the broken report, see why COUNT(*) returns 1 for customers with no orders, and fix it by counting the order ID.
Lab case 04. Find status values that change when you trim spaces and lowercase them, and keep the raw value so the team can see what needs cleaning.
Lab case 05. Use NOT EXISTS to list products that appear on order lines but have no catalog record, each one only once.
Lab case 06. Sum quantities by product for completed January orders. Counting rows instead would give you order lines, not units.
Lab case 07. Rank products by units sold with DENSE_RANK so tied products share a rank and the next rank has no gap.
Lab case 08. Total each order first, then average the order totals. Averaging item lines gives the wrong average order value.
Lab case 09. Total item lines and refunds separately, join them with a LEFT JOIN and treat missing refunds as zero to get net sales.
Lab case 10. See how joining two refunds to two item lines doubles an order's revenue, and write a query that finds every order inflated this way.
Workshop for case 10. Predict the row count of a many-to-many join, compare totals before and after, and catch the overstated orders in both datasets.
Lab case 11. Put January and February revenue side by side with two conditional sums and half-open date ranges, so no order lands in both months.
Lab case 12. Build a month list, fill empty months with zero, then use LAG to calculate month-over-month change without dividing by zero.
Workshop for case 12. See what LAG does when a month is missing and how a calendar table fixes the comparison.
Lab case 13. Find each customer's first completed order across all history, then keep the ones whose first order falls in January.
Lab case 14. Count orders per customer, then divide customers with two or more orders by customers with at least one.
Lab case 15. Number each buyer's orders with ROW_NUMBER and measure the days between the first and second purchase, including same-day repeats.
Lab case 16. Group buyers by first purchase month and count how many are active in that month and the next, keeping rows where nobody returns.
Workshop for case 16. Build the cohort table step by step: completed purchases, one row per buyer and month, acquisition month, offsets and the final counts.
Lab case 17. Start from the catalog so products without stock movements stay visible, apply the January cutoff inside the join and flag low stock.
Lab case 18. Label late, overdue and missing shipments as of an audit date with a LEFT JOIN and a CASE expression.
Lab case 19. Recalculate monthly sales from the source tables and list the months where the dashboard disagrees, with the variance.
Lab case 20, the final project. Build the monthly trading report: orders, buyers, gross sales, refunds, net sales and average order value, with empty months kept.
Workshop for case 20. Assemble the report in stages, run the control query on the second dataset and reconcile January with cases 02 and 09.
This course contains the use of artificial intelligence.
The narration in this course is an AI-generated voice-over. Our team designed and wrote every lesson to keep each one clear, structured and easy to follow.
Learn SQL by answering 20 questions an ecommerce team might ask. You’ll start with a simple one: How many orders were completed? By the end, you’ll build a monthly sales report and check that its totals match the source data.
This course is for beginners and anyone who knows a little SQL but wants more practice turning business questions into queries.
How you’ll practice
You’ll work with a sample ecommerce database in an offline SQLite lab. For each exercise, you’ll read a short brief, write and run a query, and check your results against two datasets. If something’s off, the lab shows whether the output has the expected structure and row count, and points out the first value that differs. You can open a hint when you’re stuck or compare your query with the worked solution after giving it a try.
What you’ll learn
Filter orders by date and status, join tables without losing customers, and add up item-level sales without double-counting revenue.
Calculate average order value and net sales after refunds, rank products when there are ties, and compare sales month to month.
Analyze repeat purchases and track whether customers come back based on when they first bought.
Spot low stock and late shipments, and investigate why a dashboard’s numbers differ from the source data.
Your final project
Build a monthly report that shows order counts, unique buyers, gross sales, refunds, net sales, and average order value. You’ll keep months with no orders visible and verify the totals before handing the report over.
Getting started
Download and extract the lab ZIP file, then open the lab in a desktop browser. The database runs on your computer and requires no account or separate installation. The exercises include short video walkthroughs with English captions.