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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

4 Week rolling average.. is this possible? 1

Status
Not open for further replies.

fmrock

Programmer
Joined
Sep 5, 2006
Messages
510
Location
US
Hey Everyone,

I have request, that i have no idea on how to do this in SQL and I am thinking this may have to be an application that does this.

I have the following query.

Code:
SELECT 
	CHARGES.CPCODE Site, 
	CHARGES.BILLSTATUS FC,
	Sum(CHARGES.PRAMOUNT) Payment_Amount,
	to_char(CHARGES.CURRYEAR) || '-' || to_char(LPAD(CHARGES.CURRMONTH,2,0)) || ' ' || to_char(next_day(trunc(to_date(CHARGES.POSTDATE,'j'))-7,'SUNDAY'),'YYYY-MM-DD') Week
FROM 
	CHARGES CHARGES
WHERE
	(CHARGES.TYPE='P') 
	AND (CHARGES.SPLITFLAG IS  NULL)
	AND CHARGES.POSTDATE BETWEEN to_number(to_char(trunc(sysdate,'W'),'J')-(52*7)) AND to_number(to_char(trunc(sysdate,'W'),'J'))
GROUP BY
	CHARGES.CPCODE,
	CHARGES.BILLSTATUS,
	to_char(CHARGES.CURRYEAR) || '-' || to_char(LPAD(CHARGES.CURRMONTH,2,0)) || ' ' || to_char(next_day(trunc(to_date(CHARGES.POSTDATE,'j'))-7,'SUNDAY'),'YYYY-MM-DD')

This sums up the amount of payments we get per location per financial class.

Pretty simple right? Now we have the request to create a 4 week rolling average. Basiclly for each week, we want to average the last 4 weeks, except for the most current week, it should not do the average.

is this possible? Any ideas or suggestions.

 
Works great. Thanks a bunch!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top