Divide by Sum SQL Server same table join
select a.objsub,a.bu, a.period_01a, a.period_01a/sum(b.period_01a),sum(b.period_01a)FROM FORECAST_DATA a
left outer join FORECAST_DATA b on a.bu=b.bu and b.objsub like '9991%'
where left(a.objsub,2) in ('41','53','54','55','56')
--and a.bu='021000'
group by a.objsub, a.period_01a,a.bu
select a.objsub,a.bu, a.period_01a, a.period_01a/sum(b.period_01a),sum(b.period_01a)FROM FORECAST_DATA a
left outer join FORECAST_DATA b on a.bu=b.bu and b.objsub like '9991%'
where left(a.objsub,2) in ('41','53','54','55','56')
--and a.bu='021000'
group by a.objsub, a.period_01a,a.bu
having sum(b.period_01a)<>0
No comments:
Post a Comment