Window function: lead/lag over category
Last updated: September 25, 2025
Quick Overview
Use window functions to compute running total partitioned by date.
Figma
Data Manipulation (SQL/Python)
Data Scientist
Figma
September 25, 2025Data Scientist
Technical Screen
Data Manipulation (SQL/Python)
Medium
31
7
3,206 solved
Use window functions to compute running total partitioned by date.
Data manipulation questions at Figma test your ability to work with real-world datasets. This Technical Screen question evaluates your SQL proficiency, understanding of data modeling, and ability to derive insights from raw data.
What the Interviewer Expects
- Use advanced SQL features: window functions, CTEs, subqueries
- Write efficient queries that avoid common performance pitfalls
- Handle complex data transformations with multiple joins and aggregations
- Discuss indexing strategy and query optimization
- Address data quality issues: duplicates, missing values, outliers
Key Topics to Cover
JOIN types and when to use each
Date/time manipulation
Subqueries and correlated subqueries
Index optimization and query performance
Aggregate functions and GROUP BY
Window functions (ROW_NUMBER, RANK, LAG, LEAD)
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 slowly changing dimensions in this scenario?
- How would you handle this if the data was spread across multiple databases?
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 some specified measure (e.g., sales, revenue) partitioned by date. The dataset likely contains columns such as id, date, category, and amount. The run...
Approach
- Identify the relevant columns: We will need at least
date,category, and the measure (e.g.,amount). - Use a Common Table Expression (CTE) to first aggregate data if necessary, ensuring we ...
Submit Your Answer
Markdown supported