How to Learn SQL for Data Analysis in 30 Days

By ··8 min read

Short answer

To learn SQL for data analysis, spend four weeks in this order. Start with SELECT, WHERE and aggregates, then move to joins and GROUP BY. After that, learn subqueries, CTEs and window functions, and finish with one small project that answers a business question. Practise on data you can inspect, and write down the row count you expect before you run each query.

SQL is small. The core fits in a few dozen keywords, so the keywords are not what takes time. The slow part is judgment, which means knowing when a result looks wrong. To build it, this plan assumes 45 to 60 minutes a day and a free database such as PostgreSQL or SQLite. If you can only spare 30 minutes, the plan still works, but it will take about six weeks instead of four.

The 30-day plan

WeekStudyYou can now answer
1SELECT, WHERE, ORDER BY, LIMIT, COUNT, SUM, AVGHow many orders did we get last month, and what was the average value?
2GROUP BY, HAVING, INNER and LEFT JOINRevenue by region, and which customers never ordered?
3Subqueries, CTEs, CASE, window functionsTop 3 products per category, and month-over-month growth?
4One project on a real datasetA question you chose, answered with a query and a short explanation

Week 1: read the data before you shape it

We start with the simplest job, which is reading rows. To pick the rows, we use WHERE. To summarise them, we use COUNT, SUM and AVG. Before every query, write one line, "I expect about N rows". When the result disagrees, you have found something worth understanding. A shop owner does the same when she counts the cash drawer against the till receipts before she closes.

Week 2: joins are where results go wrong

Now that we can read one table, we combine two. Learn INNER JOIN and LEFT JOIN together, and always compare the row count before and after. Most wrong dashboards trace back to a join that multiplied rows.

SELECT COUNT(*) FROM orders;                       -- 1,000
SELECT COUNT(*) FROM orders o
JOIN order_items i ON i.order_id = o.order_id;     -- more than 1,000? find out why

Week 3: write it clearly, then write it fast

A long query is hard to read, because the reader has to hold every step in mind. To name each step, we use CTEs, so another person can follow the query. Window functions come next, once joins feel natural. We also learn how NULL behaves now, since it starts to cause trouble as soon as subqueries appear.

WITH monthly AS (
  SELECT date_trunc('month', order_date) AS month, SUM(total_amount) AS revenue
  FROM orders GROUP BY 1
)
SELECT month, revenue,
  revenue / LAG(revenue) OVER (ORDER BY month) - 1 AS growth
FROM monthly;

Week 4: finish one project

Pick a dataset, write one business question, answer it in SQL and explain the number in three sentences. A short project with an explained answer shows more than twenty solved exercises, because it shows how you chose the question and checked the result.

How to practise so it sticks

  • Type every query yourself, since copying an answer teaches almost nothing.
  • Predict the result first, then run it.
  • Re-run a solved problem a week later without looking at the answer.
  • Keep a short list of mistakes, such as a join that multiplied rows or a NULL inside NOT IN.

Frequently asked questions

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

Most people can write useful queries with joins and aggregation within three to four weeks of regular practice. Window functions and NULL handling take longer to trust.

Do I need to install a database to practise SQL?

No. SQLite needs no server, and many browser-based tools let you run queries on sample data. Installing PostgreSQL is worth it once you want to work with your own datasets.

Should I learn SQL or Excel first for data analysis?

Learn the one your target job uses daily. SQL becomes necessary once data sits in a database or exceeds what a spreadsheet handles comfortably.

References

Run these queries yourself.

Predict the result, run it, and check the row count. That habit is what Practice trains.