Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cumulative totals

Status
Not open for further replies.

mjd3000

Programmer
Apr 11, 2009
136
GB
I have the following SQL and want to calculate cumulative totals for the field targ.new_numberofoutputs, grouped by Programme, Programme Contract, Output and Month. Can anybody help?

SELECT targ.new_programmemoidname AS 'Programme',
targ.new_programcontracouttidname AS 'Programme Contract',
targ.new_monthlyoutputsidname AS 'Output',
targ.new_monthnumber AS 'Month',
targ.new_numberofoutputs AS 'Target',
COUNT(act.new_outputevmonthnumber) AS 'Actual',
case when targ.new_numberofoutputs - COUNT(act.new_outputevmonthnumber) < 0 then 0 else
COUNT(act.new_outputevmonthnumber) - targ.new_numberofoutputs end AS 'Difference',
CASE WHEN targ.new_numberofoutputs = 0 THEN 0 ELSE
round(cast(count(act.new_outputevmonthnumber) as float)/targ.new_numberofoutputs * 100, 0) END as '% Achieved',
FROM FilteredNew_monthlyoutput AS targ
LEFT JOIN FilteredNew_evidence AS act
ON targ.new_monthlyprofileoutid = act.new_claimperiodid
AND targ.new_monthlyoutputsid = act.new_evidenceforoutputid
GROUP BY targ.new_programmemoidname,
targ.new_programcontracouttidname,
targ.new_monthlyoutputsidname,
targ.new_monthnumber,
targ.new_numberofoutputs
ORDER BY count(act.new_outputevmonthnumber) desc, targ.new_programmemoidname,
targ.new_programcontracouttidname,
targ.new_monthlyoutputsidname,
targ.new_monthnumber
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top