Advanced SQL
Answer analytical questions with window functions, CTEs, grouping sets and set operations, and write the deduplicating and upserting SQL that pipelines depend on.
4 objectives 6 steps about 155 min
Learn it step by step
Read the lessons in order, try the practice checks, then prove the skill with the knowledge check.
This skill page is a public outline. Its lessons and knowledge check appear here as subject-matter experts approve them.
Learning objectives
- Compute rankings, running totals, period-over-period changes and moving averages with window functions and explicit frames.
- Structure multi-step logic with CTEs, including a recursive CTE that walks hierarchical data.
- Produce multi-level summaries with GROUPING SETS or ROLLUP, pivot rows into columns (and back) with conditional aggregation or LATERAL, and compare result sets with UNION, INTERSECT and EXCEPT.
- Keep the latest record per key with ROW_NUMBER-based deduplication, apply changes to a target table with MERGE, and package the load as a parameterized SQL function or procedure.
Lesson plan
6 steps, about 155 min · 5 of 5 lessons available so far
- Window Functions: Partitions, Order and Frames Concept · 25 min
- Lab: Retention, Running Totals and Gaps-and-Islands Lab · 30 min
- Readable Step-by-Step Queries with CTEs and Recursion Worked example · 25 min
- Multi-Level Reports, Pivots and Result-Set Comparisons Lab · 25 min
- Deduplicate, MERGE and Package the Load as a Procedure Lab · 30 min
- Check: Analytical Query Challenge Knowledge check · 8 questions
Practise it
On an orders-and-events dataset, write SQL that returns monthly revenue with month-over-month growth, each customer's first and latest order, a 7-day moving average of sign-ups, a category-by-month revenue pivot, a category hierarchy built with a recursive CTE, and a deduplicated customer table maintained by a MERGE wrapped in a stored procedure; tests compare every output with expected results.
References
Hard prerequisites
Unlocks
Nothing depends on this skill yet.
On these roadmaps
Progress and evidence for this skill are shared across all of them.