HomeInterview QuestionsFor each employee, generate a new column that cont…

For each employee, generate a new column that contains the running total of salaries.

🟡 Medium Coding Junior level
1Times asked
Jul 2026Last seen
Jul 2026First seen

💡 Model Answer

You can add a running total column by using a window aggregate. Assuming you have a table called employee_payments with columns employee_id, date, and salary:

SELECT

employee_id,

date,

salary,

SUM(salary) OVER (PARTITION BY employee_id ORDER BY date ROWS UNBOUNDED PRECEDING) AS running_salary

FROM

employee_payments;

The PARTITION BY clause ensures that the running total restarts for each employee. The ORDER BY clause orders the rows chronologically, and ROWS UNBOUNDED PRECEDING includes all rows up to the current one. This query returns the original data plus a new column running_salary that shows the cumulative sum for each employee. Complexity is linear in the number of rows.

This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.

🎤 Get questions like this answered in real-time

Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.

Get Assisting AI — Starts at ₹500