SQL for Analysis: First Queries
Write SQL that answers real questions, and check that the answer is right
A taste of a lesson
I joined customers to orders and summed customer credit limits by country. The totals are way too high. Why?
That is join fan out. Each customer appears once per order after the join, so a customer with 8 orders has their credit limit counted 8 times. Credit limit lives at the customer level, but your joined table is at the order level. Fix it by summing credit limits from the customers table alone, grouped by country, or by aggregating orders per customer first and then joining. Quick check: count rows in customers, then in your joined result. What numbers do you get?
Written with AI under Skill Lab's direction as an example. In your lesson the tutor answers your own questions, and like any AI it can be wrong. Right now the AI model is not connected: replies come from a built in test engine on this site.
What you will be able to do
- Write SELECT queries with filters, sorting and limits
- Summarise data with GROUP BY, aggregates and HAVING
- Combine tables with inner and left joins correctly
- Handle NULL values without surprises
- Check query results with row counts and known totals
Lesson plan
- 1 Selecting and filtering Retrieve and filter rows to answer a simple question. Start
- 2 Summarising with GROUP BY Count, sum and average by group. Start
- 3 Filtering groups with HAVING Filter after aggregation and understand query order. Start
- 4 Joining tables Combine tables with inner and left joins. Start
- 5 NULLs and fan out Avoid the two most common wrong answers in SQL. Start
- 6 Checking your answer Verify results before sharing them. Start
Try asking
About this tutor
A free beginner tutor for analysts, marketers, product people and anyone who wants to pull their own numbers from a database. You will write SELECT queries, filter with WHERE, summarise with GROUP BY and aggregate functions, filter groups with HAVING and combine tables with joins. Every lesson pairs a business question with a small set of tables, and you learn to check results: counting rows after joins, understanding how NULL behaves and comparing totals with a known figure. The tutor notes where SQL dialects differ and keeps to standard features.
Reviews
Students can review a tutor after a paid lesson. Nobody has yet.
More like this
Other tutors on the same or nearby topics.