Back to Courses
advanced13 lessons~3h5,350 XP

Advanced SQL

CTEs, window functions, and the patterns that separate junior analysts from senior data engineers.

0%

0/13 done

Lesson Path Complete each lesson to unlock the next

Common Table Expressions (CTE)

WITH ... AS
Locked

Name your intermediate results and build complex queries in readable steps.

Complete EXISTS to unlock

Recursive CTEs

WITH RECURSIVE
Locked

Query hierarchical data and generate sequences using a CTE that references itself.

Complete Common Table Expressions (CTE) to unlock

Window Functions I — Ranking

ROW_NUMBER / RANK / DENSE_RANK
Locked

Rank rows within groups using ROW_NUMBER, RANK, and DENSE_RANK.

Complete Recursive CTEs to unlock

Window Functions II — LAG, LEAD & Running Totals

LAG / LEAD / SUM OVER
Locked

Compare rows to their neighbors and compute cumulative values without subqueries.

Complete Window Functions I — Ranking to unlock

UNION & UNION ALL

UNION / UNION ALL
Locked

Stack result sets from multiple queries vertically into one table.

Complete Window Functions II — LAG, LEAD & Running Totals to unlock

Views

CREATE VIEW
Locked

Save a query as a named virtual table that anyone can query like a real table.

Complete UNION & UNION ALL to unlock

Transactions

BEGIN / COMMIT / ROLLBACK
Locked

Group statements into one atomic unit — all succeed or all roll back.

Complete Views to unlock

Constraints: CHECK & Foreign Keys

CHECK / FOREIGN KEY / ON DELETE
Locked

Let the database itself enforce your business rules, so bad data can never get in.

Complete Transactions to unlock

Stored Procedures

CREATE PROCEDURE / CALL
Locked

Package multi-step logic — including transactions — as a single callable unit.

Complete Constraints: CHECK & Foreign Keys to unlock

Triggers

CREATE TRIGGER
Locked

Run logic automatically whenever a row is inserted, updated, or deleted.

Complete Stored Procedures to unlock

Materialized Views

MATERIALIZED VIEW / REFRESH
Locked

Cache an expensive query's result physically on disk, and refresh it on your own schedule.

Complete Triggers to unlock

Pivoting Data with CASE

Conditional aggregation pivot
Locked

Turn row values into columns — the classic spreadsheet pivot table, written in SQL.

Complete Materialized Views to unlock