How would you calculate a running total of sales?

SQL
Medium
79.7K 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 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.

Start Practicing

Related Interview Questions

Browse all 49 SQL questions