SQL Tutorial 0/85 lessons ~6 min read Lesson 76

    SQL Exercises

    Theory only sticks once you've solved real problems.

    Course progress0%
    Focus
    6 guided sections
    Practice signal
    Examples included
    Career prep
    Foundation builder

    Introduction

    Theory only sticks once you've solved real problems. This lesson is a curated set of beginner-to-advanced exercises you should run on a real DB.

    Understanding the topic

    Core concepts to understand:

    • Top-N customers by spend.
    • Find duplicates in any table.
    • Daily new sign-ups for last 30 days.
    • Most-bought products per category.
    • Users who haven't bought in 90 days.

    Syntax reference

    Visual workflow / architecture:

    bash
    Pattern bank
    1. Top-N per group → window functions
    2. Duplicates → GROUP BY + HAVING
    3. Time series → date_trunc + GROUP BY
    4. Funnel → CASE + SUM
    5. Inactive users → LEFT JOIN + IS NULL

    Real-world use

    Every interview at every product/data company tests these patterns. Solving 20 of them fluently puts you ahead of 90% of candidates.

    Best practices

    • Solve on a real Postgres/MySQL — not paper.
    • Add EXPLAIN ANALYZE for each.
    • Time yourself.

    Hands-on exercise

    Interview preparation — practice these questions:

    • Q1. Top-3 spenders per country.
    • Q2. Find duplicate emails.
    • Q3. New sign-ups per day for 30 days.
    • Q4. Funnel: signed up → activated → paid.
    • Q5. Users inactive for 90 days.
    Ready to mark this lesson complete?Track your journey across the entire course.