How would you calculate a running total of sales?

SQL
Medium
79.8K views

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…

Common Mistakes to Avoid

  • Using GROUP BY incorrectly
  • Forgetting ORDER BY in window
  • Confusing running total with average

Sound confident on this question in 5 minutes

Answer once and get a 30-second AI critique of your structure, content, and delivery. First attempt is free — no signup needed.

Try it free

Related Interview Questions

Browse all 101 SQL questions