SQL for Data Analysis: Every Lesson a Data Analyst Needs, in Order

7 min read

SQL for data analysis means writing SELECT queries to pull data out of a company’s databases, filter it, combine tables, and summarise it into the numbers a business decides on. An analyst needs about a dozen concepts to do the job well: filtering, aggregates, GROUP BY, joins, subqueries and CTEs, CASE WHEN, date functions and window functions, plus enough about keys and table design to know when data cannot be trusted.

This page is the map. It groups every SQL lesson in our series into the order we would learn them, says what each one lets you do, shows how they combine in one real analysis query, and gives a realistic study plan.

What analysts actually use SQL for

Before the lessons, here is what the work looks like. Each row is a question a manager at an Indian consumer company might ask on a Monday morning, and the SQL concept that answers it.

Business question SQL that answers it
How many orders did we get from Pune last week? SELECT with WHERE on city and date, then COUNT
What is revenue by city and by month? SUM with GROUP BY on two columns
Which customers have not ordered in 60 days? A join or subquery against the orders table, with a date function
Who are the top three sellers in each region? DENSE_RANK with PARTITION BY, filtered in a CTE
Is this month up or down on last month? LAG over a monthly total
Why does the dashboard total not match finance’s? Checking joins for duplicated rows and keys for duplicates

Notice that none of these needs anything exotic. Most analyst SQL is the same ten or so building blocks combined in different ways, which is why the order you learn them matters more than the number you learn.

The SQL lessons, grouped into a learning path

The lessons below are grouped into five stages. Work through them in this order: each stage uses what the one before it taught.

Stage 1: how databases are organised

Learn this first, briefly. You do not need to design databases to analyse them, but you do need to know why data is split across tables and what holds them together.

Lesson What you will be able to do
SQL database types Tell relational from NoSQL databases, and pick the right data type for a column
SQL commands list Name the five command groups (DDL, DML, DQL, DCL, TCL) and what each command does
DDL commands in SQL Create and alter your own tables, and answer DROP vs TRUNCATE vs DELETE
Primary key, foreign key and constraints in SQL Understand how tables link, and check a table for duplicate keys and orphan rows
Normalization in SQL See why data is split into many tables, and what 1NF, 2NF and 3NF mean

Stage 2: answering questions from one table

This is where analysis starts. By the end of this stage you can produce most of a weekly report from a single table.

Lesson What you will be able to do
SQL aggregate functions Use COUNT, SUM, AVG, MIN and MAX, and handle NULLs correctly
GROUP BY and HAVING in SQL Summarise by any column and filter the groups
CASE WHEN in SQL Bucket values into bands and build conditional totals
Date functions in SQL Extract months, add days, and calculate the gap between two dates

Stage 3: combining tables

Real questions cross tables: customers and orders, orders and products. This stage is where most analysts’ errors happen, so take it slowly.

Lesson What you will be able to do
SQL joins Combine tables with INNER, LEFT, RIGHT and FULL joins without losing or duplicating rows
Subqueries and nested queries in SQL Use one query’s result inside another, in WHERE, FROM or SELECT
CTE in SQL Break long queries into named, readable steps with WITH, including recursive CTEs
Views in SQL Save a query as a reusable virtual table that reports can read

Stage 4: analysis patterns

These separate an analyst who can pull data from one who can answer harder questions with it.

Lesson What you will be able to do
SQL window functions Rank, take running totals, compare with the previous period, and find top N per group
Delete duplicate rows in SQL Find and remove duplicates safely, keeping the right copy

Stage 5: getting hired

Lesson What you will be able to do
SQL interview questions Answer the fresher, intermediate and advanced questions asked in analyst interviews

One analysis, several lessons at once

To see how the stages combine, here is one realistic question from a Bengaluru D2C apparel brand: for each city, how many customers do we have, how many came back to order again, and what share of revenue comes from those repeat customers? Amounts are in rupees.

order_id customer_id city order_date amount
7001 C11 Bengaluru 2026-10-02 1899
7002 C12 Mumbai 2026-10-03 2499
7003 C11 Bengaluru 2026-10-09 1299
7004 C13 Bengaluru 2026-10-11 899
7005 C14 Delhi 2026-10-12 3199
7006 C12 Mumbai 2026-10-20 1799
7007 C15 Delhi 2026-10-22 1499
7008 C11 Bengaluru 2026-10-28 2199

The query, one clause per row, with the lesson each part comes from:

SQL Lesson it uses
WITH customer_city AS ( CTE
SELECT customer_id, city, COUNT(*) AS n, SUM(amount) AS spend FROM orders GROUP BY customer_id, city ) Aggregates, GROUP BY
SELECT city, COUNT(*) AS customers, Aggregates
SUM(CASE WHEN n > 1 THEN 1 ELSE 0 END) AS repeat_customers, CASE WHEN inside an aggregate
SUM(spend) AS revenue, Aggregates
ROUND(100.0 * SUM(CASE WHEN n > 1 THEN spend ELSE 0 END) / SUM(spend), 1) AS repeat_share_pct CASE WHEN, aggregates
FROM customer_city GROUP BY city ORDER BY revenue DESC GROUP BY
city customers repeat_customers revenue repeat_share_pct
Bengaluru 2 1 6296 85.7
Delhi 2 0 4698 0.0
Mumbai 1 1 4298 100.0

The reading: in Bengaluru one loyal customer (C11, three orders) produces 86% of the city’s revenue, while Delhi has no repeat buyers at all. That is a retention question for the marketing team, found in one query. On a real table you would add a date filter in a WHERE clause and a join to a customers table, and the shape would stay the same.

The step most beginners would get wrong is the first one: totalling per customer before totalling per city. Skip the CTE and count orders per city directly, and you cannot tell a city with one loyal customer from a city with three one-time buyers.

How long SQL takes to learn for analysis

The honest answer: the basics take two to three weeks, and being trusted with real data takes a couple of months of regular practice. Here is a self-study plan at about eight to ten hours a week.

Weeks Stage Practice target
1 Stage 1 and filtering Load a small dataset into MySQL or PostgreSQL; write 20 SELECT and WHERE queries
2 to 3 Stage 2 Rebuild a weekly sales report from one table using GROUP BY, CASE WHEN and dates
4 to 5 Stage 3 Answer questions across three or four joined tables; check row counts after every join
6 to 7 Stage 4 Rankings, running totals and month-on-month change on a year of data
8 Stage 5 Timed practice on interview questions, explaining each answer out loud

The gap between “finished the lessons” and “job-ready” is almost always practice volume and feedback. Writing a query that runs is easy; noticing that it double-counts is what takes reps.

Which database should you learn on?

Learn on MySQL or PostgreSQL. Both are free, both are widely used by Indian startups and product companies, and the SQL you write on one transfers to the other with small changes. SQL Server is common in large enterprises, banks and IT services firms, and if a job description names it, spend a day on its differences, mainly TOP instead of LIMIT and different date functions.

Point MySQL PostgreSQL SQL Server
First n rows LIMIT n LIMIT n TOP n
Today’s date CURDATE() CURRENT_DATE GETDATE()
Recursive CTE WITH RECURSIVE WITH RECURSIVE WITH
Window functions Version 8.0 and later Yes Yes
Cost Free Free Paid; free Express and Developer editions

Every lesson in this series points out where the three differ when it matters. For the bigger picture of database families, including the cloud warehouses such as BigQuery and Snowflake that analysts increasingly query, see SQL database types.

SQL, Excel or Python?

You need all three eventually, and they are not competing. SQL gets the data out of the database and does the heavy aggregation, on millions of rows if needed. Excel is where many business users still want the result, and where quick pivots and formatting happen. Python takes over for statistics, modelling, and automating work you would otherwise repeat every week.

If you are choosing what to learn first for an analyst role in India, learn SQL first. It appears in almost every analyst job description, it is tested in nearly every interview, and it is the fastest of the three to become useful in.

Habits that keep your numbers right

Check row counts after every join. If a table of 10,000 orders becomes 14,000 rows after a join, something has fanned out.

Know what NULL means in each column. A missing credit score and a missing payment are not the same, and AVG treats them both by skipping them.

Total at the right level. Aggregate per customer before you aggregate per city, as the worked example above does.

Write the question as a comment above the query. When a stakeholder asks what a number means three weeks later, the comment is your answer.

Run every UPDATE or DELETE as a SELECT first. Same WHERE clause, check the rows, then change them.

Frequently asked questions

What SQL do data analysts need to know?

Data analysts need SELECT with filtering, aggregate functions, GROUP BY and HAVING, all types of joins, subqueries and CTEs, CASE WHEN, date functions and window functions. They also need enough understanding of primary and foreign keys to check data quality. Database administration, stored procedures and performance tuning are useful later but rarely required for a first analyst role.

How long does it take to learn SQL for data analysis?

Most people learn the basics in two to three weeks of regular practice and reach job-ready level in about two months at eight to ten hours a week. The difference between the two is mostly practice on real, messy data, especially multi-table joins and window functions.

Is SQL enough to get a data analyst job in India?

SQL alone is rarely enough, but it is the most important single skill. Most analyst job descriptions in India also ask for Excel and a visualisation tool such as Power BI or Tableau, and many ask for basic Python. SQL is usually tested first and hardest in interviews, so it is the right place to start.

Which database is best for learning SQL?

MySQL or PostgreSQL. Both are free, widely used in Indian companies, and close enough that skills transfer between them with minor changes. Learn one properly and note the differences as you go, rather than switching between several databases while still learning the basics.

Is SQL hard to learn?

The syntax is one of the easier things in data work, because SQL reads close to English. The difficulty is in getting correct answers on real data: joins that duplicate rows, NULLs that skew averages, and totals calculated at the wrong level. Those come with practice and feedback rather than more reading.

Should I learn SQL or Python first for data analysis?

SQL first, for most people aiming at analyst roles. It is quicker to become useful in, it is tested in nearly every analyst interview, and the data you will analyse in Python usually has to be pulled out of a database with SQL first. Add Python once you are comfortable with joins and GROUP BY.

Learn SQL with someone checking your work

Reading lessons gets you the concepts. What makes you employable is writing hundreds of queries on realistic data and having someone tell you why a total is wrong before an interviewer or a manager does.

SkilloVilla’s SQL: Beginner to Advanced course follows much the same path, from fundamental statements and creating databases through aggregation, joins and advanced SQL statements, taught in live classes with mentor support and practice on SQL playgrounds. If you want SQL as part of a full analyst programme with Excel, Python, Power BI and placement support, see the Data Analytics with Python track.

Statistics for Data Analytics: The Topics an Analyst Needs,…

Statistics for data analytics: the topics an analyst uses, grouped into a learning path, with the business question each answers and a study plan.
SkilloVilla Team
6 min read

Standard Deviation and Variance for Data Analysts, With Worked…

Standard deviation and variance for data analysts: population vs sample (n vs n-1), a worked calculation, Excel and SQL functions, and what it means.
SkilloVilla Team
7 min read

Power BI vs Tableau: Which to Learn for an…

Power BI vs Tableau compared for Indian job-seekers: job demand, cost, learning curve, data prep, Mac support and sharing, with a side-by-side table.
SkilloVilla Team
5 min read

Leave a Reply