问题:
查询员工的累计薪水,Employee 表保存了一年内的薪水信息。请你编写 SQL 语句,对于每个员工,查询他除最近一个月(即最大月)之外,剩下每个月的近三个月的累计薪水(不足三个月也要计算)。结果请按 Id 升序,然后按 Month 降序显示。
Employee表:
Id | Month | Salary |
---|---|---|
1 | 1 | 20 |
2 | 1 | 20 |
1 | 2 | 30 |
2 | 2 | 30 |
3 | 2 | 40 |
1 | 3 | 40 |
3 | 3 | 60 |
1 | 4 | 60 |
3 | 4 | 70 |
输出:
Id | Month | Salary |
---|---|---|
1 | 3 | 90 |
1 | 2 | 50 |
1 | 1 | 20 |
2 | 1 | 20 |
3 | 3 | 100 |
3 | 2 | 40 |
--建表语句:
Create table If Not Exists Employee (Id int, Month int, Salary int)
Truncate table Employee
insert into Employee (Id, Month, Salary) values ('1', '1', '20')
insert into Employee (Id, Month, Salary) values ('2',