Cumulative Salary

ASKED IN INTERVIEW
10pts
Payroll

Problem Statement

Find the 3-month rolling total salary for every employee.

Rules:

  • Columns: employee_id, salary_month, rolling_three_month_salary.
  • Rolling Sum: Current month + 2 months prior.
  • Window resets per employee.
  • Sort by employee_id ASC, salary_month ASC.
Tests your understanding of
Window Functions, Rolling Sum, Finance and Analytics

Input Tables

employees
employee_id(INTEGER)name(VARCHAR)
1John
2Jane
salaries
employee_id(INTEGER)salary_month(INTEGER)amount(DECIMAL)
112000
123000
134000
145000
departments
dept_id(INTEGER)dept_name(VARCHAR)
10Finance

Expected Output

employee_id(INTEGER)salary_month(INTEGER)rolling_three_month_salary(DECIMAL)
112000
125000
139000
1412000

Tags

HardASKED IN INTERVIEWWindow FunctionsRolling SumFinanceAnalytics
25-35 min
35%

Hints