Window function: running total over user_id
Last updated: December 18, 2025
Quick Overview
Use window functions to compute rank partitioned by date.
Zoom
Data Manipulation (SQL/Python)
Data Scientist
Zoom
December 18, 2025Data Scientist
Onsite
Data Manipulation (SQL/Python)
Easy
16
1
4,598 solved
Use window functions to compute rank partitioned by date.
Zoom asks this during the Onsite because data engineering skills are critical for the role. You should be comfortable with complex joins, window functions, CTEs, and performance optimization.
What the Interviewer Expects
- Write syntactically correct SQL with proper JOIN and WHERE clauses
- Use GROUP BY and aggregate functions appropriately
- Handle NULL values correctly in your queries
- Explain the query execution plan at a high level
Key Topics to Cover
Pandas vectorized operations and groupby
Date/time manipulation
JOIN types and when to use each
Subqueries and correlated subqueries
Data cleaning and transformation
Aggregate functions and GROUP BY
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- Can you rewrite this without using subqueries?
- How would you handle this if the data was spread across multiple databases?
- How would you handle slowly changing dimensions in this scenario?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Problem Understanding
The task is to compute a running total of user activity, ranked by date, using window functions in SQL. The data involved includes user identifiers (user_id), associated activities or events, and co...
Approach
- Identify the Data Sources: Determine which tables or datasets contain the
user_id, activity, and date information. For example, we might have auser_activitytable with columns:user_id, ...
Submit Your Answer
Markdown supported