DatabaseAdvancedsql

Advanced SQL

Window functions, CTEs, recursive queries and query tuning, taught as claims about rows rather than as syntax to memorise.

Most SQL is learned as a vocabulary: SELECT, JOIN, GROUP BY, ORDER BY. That vocabulary is enough to get results, and it is also enough to write queries that are quietly wrong in a way nobody notices until the numbers are on a dashboard. This course treats a query as a claim about rows. Every advanced feature is a way of making that claim more precise: a CTE names an intermediate result instead of burying it, a window function reaches across a group without destroying it, a recursive query handles a shape with no fixed depth, and an upsert states exactly which columns a write is permitted to change. The graded work is executed. The challenges run against a real SQLite database and compare the rows your query returns, so nothing here is graded on whether your SQL resembles the answer key. Several of them are built so that a plausible wrong answer passes the cases you can see and fails the ones you cannot — because that is the actual shape of the mistake this material is about.

4.8 (120) 860 students 240 min 18 lessons 280 XP on completion

What you will be able to do

  • State the grain of a result and tell whether a GROUP BY changed it
  • Rewrite a nested query as named CTEs that a reviewer can read in order
  • Use window functions to compare a row to its partition without collapsing the partition
  • Get window frames right, and know when a default frame is quietly wrong
  • Walk a hierarchy with a recursive CTE, including the rows a recursive query cannot reach
  • Write an upsert that changes only the columns it is supposed to change
  • Read a query plan, and tell the difference between a slow query and a bad data shape

Assessments

Dashboard