Manager | Employee |HireDate
----------------------------------------
ManagerA| EmpA |1/1/2012
managerA| EmpB |1/15/2012
ManagerB| Emp C |2/1/2012
ManagerA| Emp D |2/15/2012
ManagerB| Emp E |2/8/2012
每位经理的奖金金额是根据当月雇用的新兵人数计算的。 恩。每位经理在第一次聘用时获得1000,每次获得500次。
它几乎就像每条记录都有种子
Manager | Employee |HireDate | Seed
------------------------------------------------
ManagerA| EmpA |1/1/2012 | 1
managerA| EmpB |1/15/2012 | 2
ManagerB| Emp C |2/1/2012 | 1
ManagerA| Emp D |2/15/2012 | 1
ManagerB| Emp E |2/8/2012 | 2
和Bonus是种子的函数,为1000+(种子-1)* 500
我需要帮助生成种子。我不确定是否应该使用存储过程来生成种子或函数
最终我想生成一个表格,如下所示
Manager | Employee |HireDate | Bonus
-------------------------------------------------
ManagerA| EmpA |1/1/2012 | 1000
managerA| EmpB |1/15/2012 | 1500
ManagerB| Emp C |2/1/2012 | 1000
ManagerA| Emp D |2/15/2012 | 1000
ManagerB| Emp E |2/8/2012 | 1500
答案 0 :(得分:0)
获取种子
Select
*
,ROW_NUMBER() Over(Partition By Manager, Year(HireDate), Month(HireDate) Order By HireDate) As Seed
From
YourTable
直接获得奖金
Select
*
,1000 + (Seed - 1) * 500 As Bonus
From
(
Select
*
,ROW_NUMBER() Over(Partition By Manager, Year(HireDate), Month(HireDate) Order By HireDate) As Seed
From
YourTable
) T