ROWS vs RANGE: The Silent Bug

Concepts covered: sqlWindowFrame

The canonical running total query is the one you should be able to write while talking. PARTITION BY the grouping column, ORDER BY the time column, frame clause UNBOUNDED PRECEDING to CURRENT ROW. The frame clause is what makes it a running total rather than a partition-wide aggregate. Why each clause matters PARTITION BY account_id: the running total resets at every new account. Without it, the SUM runs across every transaction in the table, regardless of which account it belongs to. ORDER BY txn_date: defines the temporal order within each partition. Without ORDER BY, the running total is undefined (the engine can return rows in any order). ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW: the frame. UNBOUNDED PRECEDING means 'from the very first row in the partition.' CURRENT ROW means

About This Interactive Section

This section is part of the Running Totals: Intermediate lesson on DataDriven, a free data engineering interview prep platform. Each section includes explanations, worked examples, and hands-on code challenges that execute in real time. SQL queries run against a live database. Python runs in a sandboxed Docker container. Data modeling problems validate against interactive schema canvases. All content is framed around what data engineering interviewers actually test at companies like Meta, Google, Amazon, Netflix, Stripe, and Databricks.

How DataDriven Lessons Work

DataDriven combines four interview rounds (SQL, Python, Data Modeling, Pipeline Architecture) with adaptive difficulty and spaced repetition. Easy problems get harder as you improve. Weak concepts resurface until you master them. Your readiness score tracks progress across every topic interviewers test. Every lesson section ends with problems you solve by writing and running real code, not by picking multiple-choice answers.