Calculate cumulative sum per user

Last updated: November 30, 2025

Quick Overview

Write a query to compute cumulative sum grouped by date, handling edge cases like nulls and duplicates.

Supabase
Data Manipulation (SQL/Python)
Data Scientist
Supabase
November 30, 2025
Data Scientist
Technical Screen
Data Manipulation (SQL/Python)
Easy

138

13

2,891 solved


Write a query to compute cumulative sum grouped by date, handling edge cases like nulls and duplicates.

This question from Supabase's Technical Screen tests practical data skills. The interviewer wants to see clean, efficient queries that handle edge cases like NULLs, duplicates, and large datasets.

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
Data cleaning and transformation
Aggregate functions and GROUP BY
Date/time manipulation
NULL handling and COALESCE
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • How would you handle this if the data was spread across multiple databases?
  • How would you handle slowly changing dimensions in this scenario?
  • How would you optimize this query for a table with 100 million rows?
  • How would you validate the correctness of your query results?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice SQL Problems
Sample Answer
Problem Understanding

To calculate the cumulative sum per user grouped by date, we need a dataset that includes at least the following columns: user_id, transaction_date, and amount. The goal is to compute a running ...

Approach
  1. Data Cleaning: Start by filtering out any rows where the amount is NULL because they do not contribute to the cumulative sum.
  2. Aggregation: Use a GROUP BY clause to sum the amounts fo...

Submit Your Answer
Markdown supported

Related Questions