If you want to become a data analyst, SQL is the single most important skill to learn — more important than Python, more important than Excel, more important than any BI tool. This guide on how to learn sql for data analysis gives you a practical week-by-week roadmap for 2026, with real analyst-style queries you can run and adapt from day one.
Follow this plan for 6-8 weeks, practice every day, and you will be able to answer genuine business questions with data — the exact skill employers test for in data analyst interviews.
Why SQL Matters So Much for Data Analysts
Every data analyst job description lists SQL first, and it is not a coincidence. The data you analyze lives in databases — company data warehouses, production systems, cloud platforms — and SQL is the universal key to all of them. Python and BI tools are powerful, but they almost always sit downstream of SQL: you use SQL to pull exactly the right slice of data, then analyze or visualize it elsewhere.
Concretely, SQL lets a data analyst:
- Pull any subset of company data in seconds without waiting on an engineer
- Join data from multiple tables (users + orders + products) into one analysis-ready dataset
- Compute metrics — revenue, conversion rates, churn, retention — directly at the source
- Validate data quality and spot anomalies before they corrupt a report
- Feed clean datasets into Python/pandas or dashboards in Tableau, Power BI, or Looker
If you are starting from zero, read our SQL tutorial for beginners first for the fundamentals, then come back here for the analyst-focused roadmap.
The 6-Week Roadmap: How to Learn SQL for Data Analysis
Week 1: SQL Basics — SELECT, WHERE, ORDER BY
Your foundation: retrieving and filtering data. Master SELECT with explicit column names, WHERE with comparison operators, AND/OR logic, and ORDER BY with LIMIT. Practice questions: “Show me all orders over $500 from last month, newest first.” If any of this feels shaky, our beginner SQL tutorial covers it with working examples.
Week 1 milestone: write 20 filtering queries against a practice dataset without looking at notes.
Week 2: Filtering Like an Analyst — LIKE, IN, BETWEEN, NULLs, Dates
Real data is messy. This week, learn pattern matching with LIKE, list filtering with IN, ranges with BETWEEN, and — critically — how NULL values behave (WHERE column = NULL never matches; you need IS NULL). Spend extra time on date functions: analysts filter by date constantly, and every database has its own date syntax (DATE_TRUNC in PostgreSQL, DATE_FORMAT in MySQL).
-- Monthly signups in 2024, excluding test accounts
SELECT DATE_TRUNC('month', signup_date) AS signup_month,
COUNT(*) AS new_users
FROM users
WHERE signup_date >= '2024-01-01'
AND email NOT LIKE '%@test.com'
AND deleted_at IS NULL
GROUP BY 1
ORDER BY 1;
Week 2 milestone: answer “how many active users signed up per month this year?” on any dataset.
Week 3: JOINs — Combining Tables
Analyst work is JOIN work: users joined to orders, orders joined to products, sessions joined to campaigns. Master INNER JOIN and LEFT JOIN deeply — understand exactly which rows survive each type — and learn to spot the classic beginner bug of accidental row duplication when a JOIN matches one row to many.
-- Revenue per customer, including customers with zero orders
SELECT c.name,
COUNT(o.id) AS orders,
COALESCE(SUM(o.amount), 0) AS revenue
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.id
GROUP BY c.name
ORDER BY revenue DESC
LIMIT 10;
Week 3 milestone: combine three tables in one query and explain every row in the result.
Week 4: Aggregations — GROUP BY, HAVING, CASE WHEN
Week 4 is the turning point in how to learn sql for data analysis: this is where you start computing real metrics. GROUP BY with COUNT, SUM, AVG; HAVING to filter groups; and CASE WHEN — SQL’s if/else — for building custom segments and buckets inside a query:
-- Orders bucketed by size segment
SELECT CASE
WHEN amount < 50 THEN 'small'
WHEN amount < 500 THEN 'medium'
ELSE 'large'
END AS order_segment,
COUNT(*) AS num_orders,
AVG(amount) AS avg_value
FROM orders
GROUP BY 1
ORDER BY avg_value;
CASE WHEN is arguably the highest-leverage single construct in analyst SQL — it turns raw data into business categories without any external tooling.
Week 4 milestone: compute conversion rates and segment-level metrics with CASE WHEN.
Week 5: Subqueries and CTEs — Structuring Complex Logic
When a question needs multiple steps (“of the customers who ordered in Q1, how many ordered again in Q2?”), you need queries inside queries. CTEs (Common Table Expressions, the WITH clause) let you build complex analysis as readable, named steps:
-- Repeat purchase rate: customers who ordered in both Q1 and Q2
WITH q1_customers AS (
SELECT DISTINCT customer_id
FROM orders
WHERE order_date BETWEEN '2024-01-01' AND '2024-03-31'
),
q2_customers AS (
SELECT DISTINCT customer_id
FROM orders
WHERE order_date BETWEEN '2024-04-01' AND '2024-06-30'
)
SELECT COUNT(*) AS q1_customers,
COUNT(q2.customer_id) AS also_ordered_in_q2,
ROUND(100.0 * COUNT(q2.customer_id) / COUNT(*), 1) AS repeat_rate_pct
FROM q1_customers q1
LEFT JOIN q2_customers q2 ON q2.customer_id = q1.customer_id;
Prefer CTEs over nested subqueries — they read top-to-bottom like a recipe, and any analyst inheriting your code will thank you.
Week 5 milestone: rewrite a three-level nested subquery as clean CTEs.
Week 6: Window Functions — The Analyst’s Superpower
Window functions (ROW_NUMBER, RANK, LAG, LEAD, running totals with SUM() OVER) compute values across rows without collapsing them like GROUP BY does. They are the difference between junior and mid-level SQL:
-- Running total of revenue over time + each day's rank
SELECT order_date,
SUM(amount) AS daily_revenue,
SUM(SUM(amount)) OVER (ORDER BY order_date) AS running_total,
RANK() OVER (ORDER BY SUM(amount) DESC) AS revenue_rank
FROM orders
GROUP BY order_date
ORDER BY order_date;
Classic window-function interview tasks: top-N per group (ROW_NUMBER() OVER (PARTITION BY category ORDER BY revenue DESC) then filter to row 1), month-over-month growth with LAG, and deduplication by keeping the latest row per ID.
Week 6 milestone: compute month-over-month growth rates and top-3 products per category.
Real Analyst-Style Example Queries
Here are the kinds of queries from this sql roadmap beginners actually run at work. Study them — interviewers love exactly these patterns.
Monthly Revenue Trend
SELECT DATE_TRUNC('month', order_date) AS month,
COUNT(*) AS orders,
SUM(amount) AS revenue,
AVG(amount) AS avg_order_value
FROM orders
WHERE order_date >= CURRENT_DATE - INTERVAL '12 months'
GROUP BY 1
ORDER BY 1;
Top Customers (Pareto Check)
SELECT customer_id,
COUNT(*) AS orders,
SUM(amount) AS lifetime_value
FROM orders
GROUP BY customer_id
ORDER BY lifetime_value DESC
LIMIT 20;
Cohort Retention Sketch
-- For each signup month, how many users ordered within 30 days?
WITH cohorts AS (
SELECT id AS customer_id,
DATE_TRUNC('month', signup_date) AS cohort_month
FROM customers
)
SELECT c.cohort_month,
COUNT(*) AS cohort_size,
COUNT(DISTINCT o.customer_id) AS ordered_within_30d,
ROUND(100.0 * COUNT(DISTINCT o.customer_id) / COUNT(*), 1) AS activation_pct
FROM cohorts c
LEFT JOIN orders o
ON o.customer_id = c.customer_id
AND o.order_date <= (SELECT signup_date FROM customers WHERE id = c.customer_id) + INTERVAL '30 days'
GROUP BY 1
ORDER BY 1;
Free Practice Resources
No sql data analysis tutorial works without hands-on practice — and the same is true for how to learn sql for data analysis. Theory without reps is worthless. These free resources give you real datasets to query:
- PostgreSQL + sample databases: install PostgreSQL free and load a sample dataset like Pagila (a DVD-rental database) — the closest thing to real analyst work.
- Mode SQL Tutorial: Mode’s free SQL tutorial for data analysts runs entirely in your browser with a real dataset — perfect for weeks 1-4 of this roadmap.
- StrataScratch / DataLemur: interview-style SQL problems from real companies — start these in week 5.
- Kaggle datasets: download any CSV, load it into SQLite or Postgres, and invent 10 business questions to answer.
Aim for 30-60 minutes of query practice daily. Consistency beats marathon sessions — SQL is a muscle.
How SQL Fits with Python, pandas, and BI Tools
Learning sql for data analysts — the practical side of how to learn sql for data analysis — does not mean learning only SQL. Here is how the pieces fit in a real analyst workflow:
- SQL first: query the warehouse to extract exactly the dataset you need — filtered, joined, aggregated. Never pull a billion raw rows into Python when SQL can give you the thousand that matter.
- Python/pandas second: for statistics, machine learning, complex transformations, or automation that SQL handles awkwardly. Our Python for data analysis with pandas guide picks up right where SQL leaves off.
- BI tools last: Tableau, Power BI, or Looker for dashboards and self-serve reporting — most of their “custom SQL” features assume you already know everything in this roadmap.
The hiring reality: SQL is the non-negotiable filter. Job postings list it first, take-home tests are SQL queries, and “I know Python but not SQL” is an instant rejection for analyst roles. Learn SQL deeply, then layer Python on top.
What’s Next
You now have a complete plan for how to learn sql for data analysis: six weeks from basic SELECT statements to window functions, with real analyst queries and free practice resources. The roadmap only works if you work it — open Mode’s tutorial or your Postgres install today and write your first ten queries.
- Start at the beginning with our SQL tutorial for beginners if any fundamentals feel shaky.
- Continue to Python for data analysis with pandas to add the second core analyst skill.
- See the bigger picture in how to learn coding from scratch.