Stop 03 · SQL for Data AnalysisProjects · 1/2

Write 20 SQL Queries Against a Sample Database

Part of the Data Analyst Roadmap

In short

Reading about SQL won't make you fluent. Twenty real queries on a real database will. This project is your net practice before the match.

Deliberate practice reps — work through a public sample database (e.g. a Chinook or Northwind-style dataset) writing queries of increasing complexity.

The jaadu bats in cricket nets facing a bowling machine with a bucket of balls.

Think of it like this

Twenty balls in the nets

A batter doesn't learn the cover drive from videos. They face ball after ball in the nets, starting slow and getting faster. Twenty queries, from easy to tricky, is your net session: each one grooves a pattern you'll use at work.

Watch it happen

The twenty-query ladder

Set up DB
Q1 to 5
Q6 to 10
Q11 to 15
Q16 to 20
Publish

1/6Load a free sample database like Chinook or Northwind into SQLite or PostgreSQL.

The big ideas

What you need to know

Question first, then SQL

Write each question in plain English above its query. That's how real requests arrive.

Increase difficulty

Start easy so you build speed, then push into joins, CTEs and windows.

Sanity-check answers

For each result, ask: does this number make sense? Check row counts after joins.

Make it portfolio-ready

A clean README with questions, queries and findings shows employers you can actually write SQL.

See it in code

Walk through the code

sql
1-- Q17: Top-selling genre in each country (Chinook)2WITH genre_sales AS (3  SELECT c.country, g.name AS genre, SUM(il.unit_price * il.quantity) AS sales4  FROM invoice_line il5  JOIN invoice  i ON i.invoice_id  = il.invoice_id6  JOIN customer c ON c.customer_id = i.customer_id7  JOIN track    t ON t.track_id    = il.track_id8  JOIN genre    g ON g.genre_id    = t.genre_id9  GROUP BY c.country, g.name10)11SELECT country, genre, sales12FROM (13  SELECT *, RANK() OVER (PARTITION BY country ORDER BY sales DESC) AS rnk14  FROM genre_sales15) ranked16WHERE rnk = 1;

1/3Join four tables and total sales per country and genre.

A starter for one of the harder queries. Table and column names follow one common Chinook version, so check your copy's schema.

Save yourself the pain

Common mistakes

Oops

Copying answers from a blog without running them.

Do this instead

Write each query yourself first, then compare. Struggling is where the learning happens.

Oops

Saving queries with no question or explanation.

Do this instead

Above each query, write the business question and one line on what the result shows.

Your mission

First five queries

~45 min

Quick check

After joining invoices to invoice lines, your total revenue looks much higher than expected. What's the likely cause?

Go deeper

  1. 1Download a free sample database and load it into a local SQL environment.
  2. 2Write 20 questions ranging from basic SELECTs to multi-table joins with CTEs.
  3. 3Check each answer against a second approach to confirm you got it right.

More projects at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge