Lesson 1 of 19
The sample database
Welcome to SQL for data analysis — using SQL not just to fetch rows, but to answer questions from data: totals, trends, rankings, comparisons. This is the SQL that powers dashboards, reports, and analytics. Every query in this course runs live — edit and re-run them. First, meet the sample data we'll analyse.
The tables
Two tables are always available in the editor. customers — who buys:
Click Run to execute the query.
Five customers, each with a city and age. And orders — what they bought:
Click Run to execute the query.
Six orders, each linked to a customer by customer_id, with a product and an amount (in naira). These two related tables — customers and their orders — are enough to demonstrate every analytics technique in this course (aggregation, joins, window functions, and more). Run the queries above to see the data.
From "fetching rows" to "answering questions"
Basic SQL fetches rows (SELECT * FROM orders WHERE amount > 1000). Analytical SQL answers business questions:
- "What's our total revenue?" (aggregation)
- "Which city generates the most revenue?" (grouping + joining)
- "Rank customers by spending." (window functions)
- "How did revenue change month over month?" (time-series analysis)
These need aggregation, joins, window functions, and CTEs — the tools this course teaches. You'll go from retrieving data to analysing it.
A first analytical query
Click Run to execute the query.
This summarizes all orders into a single row of answers: how many orders, total revenue, and average order value. Notice it doesn't return individual rows — it aggregates them into metrics. That's the essence of analytics: collapsing many rows into meaningful numbers. Run it — those three numbers answer questions about the business. Everything ahead builds on this idea.
Creating richer data when needed
Click Run to execute the query.
For time-series analysis (running totals, month-over-month), we'll sometimes create a small dated table like monthly_sales right in the query (as above) — since the editor runs whatever SQL you give it. So you'll see some lessons create their own sample data, then analyse it. For now, know that customers and orders are always there, and we can add richer data when a technique needs it.
The mistake beginners make
Thinking SQL is only for retrieving rows — its real power for analysis is aggregating, joining, and computing over data to answer questions. Also, not exploring the data first (always look at your tables — SELECT * — before analysing). This course assumes you know basic SQL (SELECT, WHERE, ORDER BY — from SQL & Databases Essentials); here we build the analytical layer on top. Get familiar with the sample data, and let's start answering questions with it.
Your turn
Click Run to execute the query.
Your turn
- Meet the sample data: customers (name, city, age) and orders (customer_id, product, amount) — run SELECT * on each.
- Understand analytical SQL answers questions (totals, trends, rankings) by aggregating/joining, not just fetching rows.
- See that a query can create its own richer (e.g. dated) sample data when a technique needs it.
Key points
- This course uses SQL to ANSWER QUESTIONS from data (totals, trends, rankings) — analytics, not just fetching rows.
- Two tables are always seeded: customers (name/city/age) and orders (customer_id/product/amount) — related by customer_id.
- Analytical queries collapse many rows into meaningful metrics (COUNT/SUM/AVG) — the essence of aggregation.
- For time-series analysis, a block can CREATE its own dated sample table inline; explore your data (SELECT *) before analysing.
Q&A · 0
Enrol to ask questions and join the discussion.
No questions yet — be the first to ask.