Add a new column called running salary to the dataset, computing the cumulative sum of salaries.
💡 Model Answer
To add a running salary column you can use a window function in SQL:
UPDATE employee_payments
SET running_salary = sub.running_salary
FROM (
SELECT
id,
SUM(salary) OVER (ORDER BY date ROWS UNBOUNDED PRECEDING) AS running_salaryFROM employee_payments
) AS sub
WHERE employee_payments.id = sub.id;
If you prefer to create a new table or view, simply select the columns plus the windowed sum as shown in the previous example. In pandas you would do:
df['running_salary'] = df['salary'].cumsum()
Both methods produce a column that accumulates the salary values in the order of the date column.
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