Exercise 5οΌ579.Find Cumulative Salary Of An Employee Problem
1.Description
The Employee table holds the salary information in a year.
Write a SQL to get the cumulative sum of an employeeβs salary over a period of 3 months but exclude the most recent month.
The result should be displayed by βIdβ ascending, and then by βMonthβ descending.
Example Input
Output
Explanation:Employee β1β has 3 salary records for the following 3 months except the most recent month β4β: salary 40 for month β3β, 30 for month β2β and 20 for month β1β So the cumulative sum of salary of this employee over 3 months is 90(40+30+20), 50(30+20) and 20 respectively.
Employee β2β only has one salary record (month β1β) except its most recent month β2β.
Employ β3β has two salary records except its most recent pay month β4β: month β3β with 60 and month β2β with 40. So the cumulative salary is as following.
2.Create Table and insert into values
Last updated