Window Functions and Time Series Analytics Questions
Advanced SQL window functions: ROW_NUMBER, RANK, DENSE_RANK, LAG, LEAD, and aggregate functions (SUM, COUNT, AVG) with OVER and partition clauses. Using window functions to solve practical problems: ranking users or events within segments, calculating running totals and cumulative metrics, identifying trends and transitions over time, detecting patterns in user behavior sequences. Applications: cohort retention analysis (calculating retention rates across cohorts), user lifetime value trends, engagement metrics over time windows, and sequential user actions.
EasyTechnical
67 practiced
Given users(id INT, user_email TEXT, created_at TIMESTAMP, last_login TIMESTAMP) which may contain duplicate emails, write a SQL query using ROW_NUMBER() to deduplicate and keep only the latest created_at row per user_email (ties broken by last_login). Provide sample rows and the expected deduplicated output.
EasyTechnical
63 practiced
Scenario: You maintain SQL definitions for windowed metrics (e.g., 7-day rolling active users). How would you document and communicate those SQL-based metric definitions to analysts so the business uses consistent numbers? Describe required artifacts, examples, and lifecycle steps.
MediumTechnical
55 practiced
When using Spark SQL to compute window functions over very large event tables, what execution and memory considerations should you account for? Describe specific strategies such as repartitioning, broadcast joins, adjusting shuffle partitions, and avoiding skew. Provide example Spark SQL or DataFrame snippets illustrating repartitioning before windowing.
MediumTechnical
53 practiced
Compare approaches to enrich events with the most recent user profile as of event_time: (A) computing latest profile per user using window functions and joining, (B) temporal range joins, (C) doing enrichment in the pipeline (stateful). Discuss consistency, complexity, and performance trade-offs for analytics at scale.
EasyTechnical
63 practiced
Explain the differences between ROW_NUMBER, RANK, and DENSE_RANK window functions in SQL. In your answer: 1) describe how ties are handled by each function; 2) show a small example table of user_id and score and the resulting output for each function; 3) list typical use-cases where you would choose one over the others.
Unlock Full Question Bank
Get access to hundreds of Window Functions and Time Series Analytics interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.