0
Мне нужна помощь, рассчитывающая среднюю стоимость прокатки 3 месяца из двух наборов данных ниже. Который составляет 3 месяца Среднее от набора данных1/Набор данных 2. Я не уверен, что использование cte - правильный маршрут. Любое понимание очень ценится.3 месяца Подвижность Среднее
Dataset 1:
SELECT(factAdmissions.ContractCode + '-' +factAdmissions.BenefitPlanCode) AS [Contract Code],
factAdmissions.AdmitCCYYMM,
ISNULL(sum(AmountPaid),0)As [Amount Paid]
FROM factAdmissions
WHERE factAdmissions.AdmitCCYYMM >='200701'
AND factAdmissions.AcuteSNFIndAdmit ='a'
AND factAdmissions.ContractCode Is Not Null
AND factAdmissions.BenefitPlanCode Is Not Null
AND BusinessUnitCode In('EP','HF', 'VN')
AND AdmitCCYYMM BETWEEN (@StartDate) AND (@EndDate)
AND factAdmissions.ContractCode + '-' +factAdmissions.BenefitPlanCode IN (@Product)
Group by factAdmissions.ContractCode,
factAdmissions.BenefitPlanCode,
factAdmissions.AdmitCCYYMM
Order by factAdmissions.ContractCode,
factAdmissions.BenefitPlanCode,
factAdmissions.AdmitCCYYMM;
Dataset2:
Select
(factMembership.ContractCode+'-'+ factMembership.BenefitPlanCode) As Product,
EffectiveCCYYMM,
ISNULL(count(Distinct MemberId),0) As MemberCount
From factMembership
Where EffectiveCCYYMM >= '200701'
AND BusinessUnitCode In('EP','HF', 'VN')
AND EffectiveCCYYMM BETWEEN (@StartDate) AND (@EndDate)
AND factMembership.ContractCode + '-' +factMembership.BenefitPlanCode IN (@Product)
Group by
ContractCode,
BenefitPlanCode,
EffectiveCCYYMM
Order by 1;
Dataset 1: Output 201101 201102 201103
Cost $420,627 $73,608 $93,792
Dataset 2:Output 201103
Memberscount 400
Desired Output: 201103
3 Month Rolling Average $490.02
возможно дубликат [Moving Average/скользящее среднее] (http://stackoverflow.com/questions/20408060/moving-average-rolling-average) – Allan