48. Trailing 3 Calendar Days (Range Frame)
Difficulty: Hard · Topics: Window Functions, Dates, Filtering & Selection
An advanced problem: unlock it to open the statement, sample data and editor. Graded on 3 test cases.
Learn the concepts
- Parsing dates and timestamps · 4 min read. to_date, to_timestamp and date_format patterns, and why yyyy and YYYY are not the same.
- rangeBetween · 6 min read. Window frames by value instead of row count: the last 7 calendar days, not the last 7 rows.
- row_number / rank · 4 min read. Number and rank rows inside a window, and how the three ranking functions treat ties.
PySpark functions you'll practise
- Range Between
- Window spec
- sum
- datediff
- select
- withColumn
- orderBy
Related problems
- Sessionize a Clickstream · Hard · Window Functions, Dates, Null Handling, Conditional Logic, Filtering & Selection
- Three-Day Login Streak · Hard · Window Functions, Aggregations, Dates, Filtering & Selection
- Build an SCD Type 2 History · Hard · Window Functions, Null Handling, Filtering & Selection
- Forward-Fill Missing Readings · Hard · Window Functions
- Consecutive Status Runs (Gaps and Islands) · Hard · Window Functions, Aggregations
Browse
Topics: Window Functions · Joins · Aggregations · Pivot, Unpivot & Rollup · Arrays · Null Handling · Conditional Logic · Dates · Filtering & Selection · Strings · Data Lake · Lakehouse · Streaming · Data Prep for AI · Spark Performance
Difficulty: Easy · Medium · Hard · Learn · All problems · dbt practice