我有一个报告,其中我计算国家和SubRegions的报价。现在我有许多国家为空的引号。
Table
Quote Number | Country | Subregion | Quote Count
12233 | Germany | EMEA | 100
2223 | Blank | EMEA | 3333
3444 | France | EMEA | 200
455454 | Spain | EMEA | 300没有Null国家的总报价等于1000,与德国等相关的10%,因此德国加权系数为0.1。
因此,我总共有3333个国家/地区字段为空的引号。因此,我被要求获取EMEA的报价,并使用基于当前报价分布的加权系数在德国、西班牙、法国和其他EMEA国家/地区分发报价,然后将报价添加到该地区其他国家/地区的报价中。
那么现在我完全不知道该怎么做了?有什么想法吗?
帮帮忙?有人吗?
第1步-获取EMEA中所有国家/地区的当前权重系数。在sql中?
第2步-获取未为EMEA分配国家/地区的报价的报价计数。在sql中?
第3步-获取报价,并根据加权系数将x个报价添加到每个国家/地区。在sql中?
发布于 2012-07-19 00:01:21
根据示例中的数据:
WITH Factors
AS ( SELECT Country ,
SUM([Quote Count])
/ CAST(( SELECT SUM([Quote Count])
FROM dbo.quotes
WHERE Region = q.Region
AND Country IS NOT NULL
) AS FLOAT) AS WeightingFactor ,
q.Region
FROM dbo.quotes q
WHERE country IS NOT NULL
GROUP BY q.Country ,
q.Region
)
SELECT q.country ,
( SELECT SUM([quote count])
FROM dbo.quotes
WHERE Country IS NULL
AND Region = q.Region
) * f.WeightingFactor + SUM(q.[Quote Count]) AS [Quote Count]
FROM dbo.quotes q
JOIN Factors f ON q.Country = f.Country
AND q.Region = f.Region
WHERE q.Country IS NOT NULL
GROUP BY q.Country ,
q.Region ,
WeightingFactor发布于 2012-07-18 23:42:53
要获得权重因子,请执行以下操作:
select country, quotecount,
quotecount*1.0/sum(quotecount) over (partition by null) as allocp
from t
where country <> 'Blank'若要重新添加这些内容,请加入总数:
select t.country, t.region, t.quotecount,
(t.quotecount + allocp*b.BlankBQ) as AllocatedQC
from (select country, quotecount,
quotecount*1.0/sum(quotecount) over (partition by region) as allocp
from t
where country <> 'Blank'
) t join
(select sum(QuoteCount) as BlankBQ
from t
where country = 'Blank'
group by region
) b
on t.region = b.regionhttps://stackoverflow.com/questions/11544808
复制相似问题