SQL, Actually

13 modules · 78 lessons · 2.5 hours of video

The course

Work through it in order. Each lesson is one question from the ShopKart team, a short video, and a query to run yourself.

Your progress on this device

0 of 78 lessons done

Start lesson 0.1

Foundations

0

Welcome

Understand what a database is and why SQL matters, and run your first query within ten minutes.

3 lessons · 6 min

  1. 0.1Why SQL still runs the worldFree2:00
  2. 0.2Tables, rows and columnsFree2:05
  3. 0.3Meet ShopKartFree“Welcome aboard! 👋 We've never had an analyst before. Our data's all in Postgres. Have a look around and let me know what you find.”2:23
1

First Queries

Read any single table: choose columns, calculate new ones, sort, and limit.

5 lessons · 9 min

  1. 1.1Your first queryFree“Can you send me everything we sell? Just the full product list.”1:38
  2. 1.2Picking columns & aliasesFree“Too much! I only need name, brand and price. And can the price column say price in rupees?”1:48
  3. 1.3Calculated columnsFree“What's our margin on each product — in rupees and in percent?”1:54
  4. 1.4Sorting with ORDER BYFree“Which products are the most expensive? Top of the list, please.”1:30
  5. 1.5LIMIT, OFFSET & DISTINCTFree“Which cities are our customers in? Just the list, no repeats. And the 10 newest signups.”1:48

Mini project The catalog report

2

Filtering

Return exactly the rows you want, and understand how NULL breaks intuition.

6 lessons · 11 min

  1. 2.1WHERE & comparisonsFree“Which products are out of stock right now?”1:38
  2. 2.2AND, OR, NOT“Prime members in Mumbai or Pune. I want to invite them to an event.”2:03
  3. 2.3IN & BETWEEN“Orders shipped to our 6 metro cities during the Diwali sale — 12 to 22 October. How many?”2:06
  4. 2.4Pattern matching with LIKE“Can you find every product that mentions "wireless" in its name? It's for a gadgets promo.”1:50
  5. 2.5NULL — the value that isn't there“How many customers haven't given us a phone number? Planning an SMS campaign.”2:00
  6. 2.6Filtering by date & time“Closing the books for May — can you pull every order from May?”1:47

Mini project The fraud desk

3

Functions

Transform values: clean text, round numbers, work with dates, and write if/else logic.

6 lessons · 11 min

  1. 3.1Text functionsFree“The customer list is a mess — emails in random CAPS, extra spaces at the front. Can you clean it for the newsletter?”1:51
  2. 3.2Number functions“Margins with one decimal place, and GST prices rounded to the rupee, please.”1:54
  3. 3.3Working with dates“Which month do people sign up most? And how long do deliveries take?”1:49
  4. 3.4CASE WHEN“Can you tag every product with a price tier — Budget, Mid-range or Premium?”1:47
  5. 3.5COALESCE & NULLIF“Blank phone numbers look broken in the call-centre export. Can it say "Not provided" instead?”1:40
  6. 3.6Data types & CAST“Why is 10 less than 9 in this report?”1:38

Mini project Clean the customer list

4

Aggregation

Summarise data: totals, averages, counts per group. This is the first module where SQL feels like analysis.

6 lessons · 12 min

  1. 4.1Aggregate functionsFree“What's our total revenue, and what's the average order value?”1:51
  2. 4.2GROUP BY“Total revenue is great — but I need it month by month. Did the Diwali sale actually help?”1:45
  3. 4.3Grouping by several columns“Show me orders by city AND status — I want to see where the cancellations happen.”1:36
  4. 4.4HAVING vs WHERE“Planning pop-up events — which cities have more than 50 customers?”1:41
  5. 4.5The order SQL runs“Why does WHERE say my column <i>margin</i> doesn't exist? ORDER BY margin works fine. Is Postgres broken?”3:10
  6. 4.6Conditional aggregation“One row per month: total orders, cancelled orders, and the cancellation rate — side by side.”1:48

Mini project The monthly business review

Core

5

Joins

Combine tables confidently, and know exactly how many rows a join will return before running it.

8 lessons · 16 min

  1. 5.1Why data lives in many tablesFree“Why can't the orders table just include the customer's name and city? Wouldn't one big table be simpler?”1:35
  2. 5.2Primary & foreign keys“Before you join anything — make sure you know how the tables connect.”1:42
  3. 5.3INNER JOIN“For each order, I need the customer's name next to it.”3:41
  4. 5.4LEFT JOIN“Which customers signed up but never ordered? I want to send them a coupon.”1:44
  5. 5.5RIGHT & FULL OUTER JOIN“Reconciliation time: every order should have a payment, every payment an order. Anything without a match?”1:44
  6. 5.6Joining three or more tables“Revenue by category, please — smartphones vs earbuds vs kitchen stuff.”1:41
  7. 5.7Self join & CROSS JOIN“Who referred whom? I want to reward our top referrers.”1:42
  8. 5.8Join traps“Your revenue number is higher than what the bank says.”1:50

Mini project The customer 360

6

Subqueries & CTEs

Break hard questions into steps, using queries inside queries and readable WITH blocks.

6 lessons · 11 min

  1. 6.1Subqueries in WHEREFree“Which products are priced above our average price?”1:49
  2. 6.2IN & NOT IN subqueries“Gadgets newsletter: which customers have bought anything from Electronics?”2:05
  3. 6.3EXISTS & NOT EXISTS“Which products do we stock that have never had a single order?”1:51
  4. 6.4Correlated subqueries“Is each product priced above the average of its OWN category? Earbuds vs phones isn't fair.”1:52
  5. 6.5CTEs — WITH“Which cities have the most loyal customers? Average orders per customer, per city.”1:42
  6. 6.6Recursive CTEs“Need the full category path for breadcrumbs — like "Electronics › Mobiles › Smartphones".”1:55

Mini project The product performance audit

7

Set Operations

Stack and compare query results vertically.

2 lessons · 4 min

  1. 7.1UNION vs UNION ALLFree“One activity timeline for a customer — every order and every review, in a single list, by date.”1:49
  2. 7.2INTERSECT & EXCEPT“Who ordered in 2025 but hasn't ordered at all in 2026? Who did we lose?”1:45

Mini project Who did we lose?

8

Window Functions

Calculate across related rows without collapsing them: rankings, running totals, and comparisons with the previous row.

8 lessons · 14 min

  1. 8.1What is a window?Free“Show each payment right next to the overall average — I want to spot the unusually big ones.”1:36
  2. 8.2PARTITION BY“Each product's price vs its OWN category's average — side by side, please.”1:29
  3. 8.3ROW_NUMBER, RANK, DENSE_RANK“Can you rank all our products by price? Hmm — what happens with ties?”1:31
  4. 8.4Top-N per group“For the homepage: the top 3 bestsellers in EACH category, please.”1:31
  5. 8.5Running totals“For the investor update: cumulative revenue by month. When did we cross ₹1 crore?”1:51
  6. 8.6Frames: moving averages“Daily orders are way too noisy to read. Can I get a 7-day moving average?”2:05
  7. 8.7LAG & LEAD“Month-over-month revenue change for 2025 — in rupees and in percent, please.”1:39
  8. 8.8NTILE, FIRST_VALUE, LAST_VALUE“Split customers into 4 spending tiers for the loyalty programme. And each customer's first and latest order?”2:01

Mini project Leaderboards

Advanced

9

Building Databases

Go from reading data to designing and changing it: tables, constraints, inserts, updates, and good schema design.

7 lessons · 14 min

  1. 9.1Designing a schemaFree“We're launching a seller marketplace. Can you sketch the tables before I build them?”2:17
  2. 9.2CREATE TABLE & data types“Great design. Now write the DDL for sellers?”2:03
  3. 9.3Constraints“Someone inserted a rating of 7 last time. Can we make the database refuse bad data?”2:10
  4. 9.4INSERT“Three new sellers onboarded today — Lakshmi Traders, Rao Electronics, Dilli Kart. Add them?”1:43
  5. 9.5UPDATE & DELETE“Increase prices of all Accessories by 5%. Carefully.”2:00
  6. 9.6ALTER, DROP, TRUNCATE“We need a gst_number column on sellers — and the old temp tables gone.”2:01
  7. 9.7Normalization“The sellers team lives in this spreadsheet. Is it normalized? And should it be?”2:13

Mini project Build the seller marketplace

10

Performance & Reliability

Understand what the database does with your query, make slow queries fast, and keep data consistent when things fail.

6 lessons · 12 min

  1. 10.1EXPLAINFree“The revenue-by-city dashboard will run on millions of orders next year. What is Postgres actually doing with it?”2:06
  2. 10.2Indexes“Finding one customer by email scans every row. Can you fix it?”1:59
  3. 10.3When indexes don't help“I added indexes, but some queries still scan every row. Why?”1:53
  4. 10.4Transactions“A payment was recorded but the order was never marked paid — the server crashed mid-way. How do we prevent this?”1:51
  5. 10.5ACID & concurrency“Two people bought the last unit at the same second. We sold stock we didn't have.”2:00
  6. 10.6Views & materialized views“Can you save the customer-360 query so the team can just SELECT from it?”1:56

Mini project Make the dashboard fast

11

Real-World Analytics

Combine everything into the analyses companies actually pay for: growth, funnels, cohorts, segmentation.

7 lessons · 14 min

  1. 11.1Pivoting dataFree“One row per city, one column per payment method — like a spreadsheet pivot.”1:46
  2. 11.2Date spines & filling gaps“Your daily chart skips days with zero orders. The line looks wrong.”1:55
  3. 11.3Growth: MoM & YoY“Was Diwali 2025 better than Diwali 2024? By how much?”2:13
  4. 11.4Conversion funnels“Of people who view a product, how many actually buy? Where do we lose them?”2:02
  5. 11.5Cohort retention“Do customers who joined in Diwali 2024 stick around better than others?”2:06
  6. 11.6RFM segmentation“Segment customers so marketing can target Champions and At-Risk separately.”1:49
  7. 11.7Data quality & deduplication“Before we trust any of this — how clean is the data?”2:00

Mini project The growth review

Career

12

Interview Prep

Recognise the classic SQL interview patterns instantly and solve them out loud under time pressure.

8 lessons · 16 min

  1. 12.1How SQL interviews workFree“Which city had the highest revenue last month?”2:07
  2. 12.2Nth highest value“Find the second most expensive product.”2:15
  3. 12.3Duplicates: find & delete“Find duplicate customers by email and keep only the oldest.”1:38
  4. 12.4Consecutive days: gaps & islands“Find customers who ordered on 3 or more consecutive days.”1:59
  5. 12.5Bought X but not Y“Customers who bought a phone but never a phone case.”1:38
  6. 12.6Rapid fire: window questions1:58
  7. 12.7Median & percentiles“What's the median order value? And the 90th percentile?”1:54
  8. 12.8Mock interview2:20