我创建了一个从各种方法收集销售数据的表。该表中的部分信息是:
salespersonid netSales
90 12428660.00
90 300000.00
90 250379.00
90 170061.50
650 163250.00
我必须根据下表计算佣金:
ServiceFeeRebateTypeId SalesPersonId ServiceFeeRate SamFundRate SalesLimitStart SalesLimitEnd IncludeInTier RebateName
2 115 4.00 1.00 0.00 NULL 0 Sales Rep
2 116 4.00 1.00 0.00 NULL 0 Sales Rep
2 116 4.00 1.00 0.00 NULL 0 Sales Rep
3 NULL 6.00 0.50 0.00 NULL 0 Owner
3 NULL 5.00 0.50 0.00 NULL 0 Owner
1 NULL 5.00 0.50 0.00 NULL 0 Customer
1 NULL 5.00 0.50 0.00 NULL 0 Customer
1 NULL 3.00 0.25 0.00 NULL 0 Customer
4 NULL 8.00 1.00 0.00 50000.00 1 Tier1
5 NULL 7.00 0.75 50000.01 100000.00 1 Tier2
6 NULL 6.00 0.50 100000.01 NULL 1 Tier3
3 NULL 4.00 5.00 0.00 NULL 0 Owner
3 NULL 6.00 0.50 0.00 NULL 0 Owner
4 NULL 7.00 0.75 50000.00 100000.00 1 Tier1
5 NULL 6.00 0.25 100001.00 416666.00 1 Tier2
4 NULL 12.00 1.00 0.00 50000.00 1 Tier1
1 NULL 2.00 3.00 0.00 NULL 0 Customer
5 NULL 5.00 5.00 50000.00 100000.00 0 Tier2
4 NULL 0.25 0.50 0.00 50000.00 0 Tier1
5 NULL 0.50 1.00 50000.01 100000.00 0 Tier2
2 NULL 6.00 0.50 0.00 NULL 1 Sales Rep
2 875 5.00 0.25 0.00 NULL 0 Sales Rep
以下示例是需要考虑的因素: Bob在1月份从客户付款中获得175,000美元,所有这些都包含在等级销售中。
Bob的第1层是0 - 50,000 - 服务费率= 8.00%,Sam Fund Rate = 1.00%所以他的“服务费”总计9.00%
鲍勃的第2层是50,000.01 - 100,000 - 服务费率= 7.00%,Sam基金利率= .50%,所以他的“服务费”总计7.50%
Bob的Tier 3为100,000 - 9,999,999 - 服务费率= 6.00%,Sam Fund Rate = .25%,因此他的“服务费”总计为6.25%
Tier Rebate Sales Range Sales Amount Percent Rebate Amount Total
Tier 1 0 to 50,000 50,000 0 0 0
Tier 2 50,000.01 to 100,000 50,000 1.50% (which is calculated by Subtracting the Tier 1 Service Fees 9% - Tier 2 Service 7.5%) $750 - Which is the Sales Amount * the percent $750
Tier 3 100,000.01 to 9,999,999 75,000 2.75% (which is calculated by Subtracting the Tier 1 Service Fees 9% - Tier 3 Service 6.25%) $2062.50 - Which is the Sales Amount * the percent 2812.5
Grand Total 2812.5
我使用CASE语句完成了匹配的其他几个条件。 这个计算也需要计算,但我正在努力设置。