当前位置:   article > 正文

leetcode 579查询员工的累积薪水_leetcode 查找员工的累计薪水

leetcode 查找员工的累计薪水

Employee表中有一年的员工薪资信息,写一个sql来获得3个月内员工工资的累计总和,但不包括最近一个月
在这里插入图片描述
方法一,待验证

select a.Id,a.Month, sum(Salary) as cu_salary
from Employee as a
join Employee as b on a.Id=b.Id and a.Month<=b.Month
join(
	select Id, max(month) as max_mon
	from Employee
	) as c on a.Id=c.Id and a.month between (c.max_mon-3) and (c.max_mon-1)
group by a.Id, a.Month
order by id, Month desc
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

方法二

select a.Id, max(B.Month) as Month, sum(B.Salary) as Salary
from Employee as a
join Employee as b
on a.Id=b.id and B.Month between (c.max_mon-3) and (c.max_mon-1)
group by a.Id, a.Month
order by id, Month desc
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/空白诗007/article/detail/950221
推荐阅读
相关标签
  

闽ICP备14008679号