我的设置中有两个表。一个是有销售人员和收入的。每个销售人员只知道他们的总收入。在这一特定的收入期间,他们被要求对私人、小型企业或大型企业客户的收入进行估计。此信息被输入到第二个表中。
Income
=================
SalesPerson
Income
Distribution
=============================
SalesPerson
CustomerType
Weight现在,我的查询如下所示:
SELECT
Income.SalesPerson,
Distribution.CustomerType,
Income.Income * Distribution.Weight as DistributedIncome
FROM
Income INNER JOIN Distribution ON
Income.SalesPerson = Distribution.SalesPerson我如何强制Distribution中的每个SalesPerson的SUM(Weight) =1
发布于 2012-02-17 23:38:13
根据相同的标准,按总和进行归一化。
SELECT
Income.SalesPerson,
Distribution.CustomerType,
Income.Income * Distribution.Weight/(
select sum(d.weight)
from distribution d
inner join income i on i.salesperson = d.salesperson
)
as DistributedIncome
FROM
Income INNER JOIN Distribution ON
Income.SalesPerson = Distribution.SalesPerson如果以某种方式想要选择和为1的未修改的权重,那么我相信你有一个subset sum problem的例子,你可能不能用一个SQL查询来解决这个问题。
https://stackoverflow.com/questions/9331007
复制相似问题