Calculate Running Total of Employee Salaries

Calculate the running total of salaries ordered by employee hire date.

sql

SELECT name, hire_date, salary, SUM(salary) OVER (ORDER BY hire_date) AS running_total FROM employees;

This query uses the SUM() window function with an ORDER BY clause to calculate the cumulative sum of the salary column, partitioned by the chronological order of the hire_date.

PromptDB can make mistakes. Please double-check responses.