1
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

奖金是种子的函数,为 1000+(seed-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
4

1 回答 1

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
于 2012-10-10T19:12:10.557 回答