如何通过表格中员工的增量获得更新的薪水 [英] How do i get the updated salary with increment of the employee in my table
问题描述
我有桌子employee_details
id日期名称工资
1月15日james 10000
2 2月15日卡车20000
3月15日查尔斯30000
4月15日杰克40000
5月15日jani 50000 >
6月15日债券60000
i需要输出为
id日期名称工资updated_salary
1月15日james 10000 10000(工资1)
2月15日carie 20000 30000(id2 + id1的工资)
3月15日查尔斯30000 50000(id4 + id3的工资)
4月15日jackie 40000 70000(id5 + id4的工资)
5月15日jani 50000 90000(id6 + id5的工资)
6月15日债券60000 110000(id7 + id6的工资)
我尝试了什么:
i尝试使用while循环迭代但是没有得到所需的输出我需要
i have table employee_details
id date name salary
1 Jan-15 james 10000
2 Feb-15 carie 20000
3 Mar-15 charles 30000
4 Apr-15 jackie 40000
5 May-15 jani 50000
6 Jun-15 bond 60000
i need output as
id date name salary updated_salary
1 Jan-15 james 10000 10000 (salary of id 1
2 Feb-15 carie 20000 30000 (salary of id2+ id1)
3 Mar-15 charles 30000 50000 (salary of id4+ id3)
4 Apr-15 jackie 40000 70000 (salary of id5+ id4)
5 May-15 jani 50000 90000 (salary of id6+ id5)
6 Jun-15 bond 60000 110000 (salary of id7+ id6)
What I have tried:
i have tried with while loop iteration but am not getting the required output as i need
推荐答案
加入同一数据集的上一个记录:
Join to the "previous" record of the same dataset:
select curr.*, curr.salary + COALESCE(prev.salary, 0) as updated_salary
from employee_details curr
left join employee_details prev on prev.id = curr.id - 1
这篇关于如何通过表格中员工的增量获得更新的薪水的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!