How would you calculate a running total of sales?
This question tests window function proficiency. It evaluates analytical query skills.
Why Interviewers Ask This
Running totals are common business metrics. Interviewers check if you know window functions instead of self-joins or cursors. This shows modern SQL fluency.
How to Answer This Question
Identify SUM() OVER() as the solution. Explain PARTITION BY for grouping and ORDER BY for sequence. Define the frame for accumulation.
Key Points to Cover
- Window function usage
- Partitioning logic
- Ordering for accumulation
- Frame specification
Sample Answer
I would use a window function to compute the sum over rows of the same product, ordered by time. Using SUM(amount) OVER (PARTITION BY product_id ORDER BY sale_date) accumulates the total from the start up to the current row, keeping row detail while adding the running total.
Common Mistakes to Avoid
- Using GROUP BY incorrectly
- Forgetting ORDER BY in window
- Confusing running total with average
Practice This Question with AI
Answer this question orally or via text and get instant AI-powered feedback on your response quality, structure, and delivery.
Related Interview Questions
Describe a PRIMARY KEY and how it differs from a UNIQUE key
Medium
What is ER model in the DBMS?
Medium
FlipkartWhat is the difference between LIKE and equals operators in SQL?
Easy
TCSWhat is the difference between UNION and UNION ALL?
Easy
What is Join and explain its types?
Medium
FlipkartWhat is the ER model in DBMS?
Easy
Flipkart