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!

Aggregate Values (SUM, AVG and Tot_Val) in a View

Status
Not open for further replies.

karlomutschler

Programmer
Jun 5, 2001
75
DE
Hi all,
I have created a view that displays the following info.

Turnover Total
Contract ID Jan Feb Mar ... Dec YTD AVG Value
533976 62,88 46,76 17,76 ? 68,88
1669463 60,25 79,63 49,94 68,00 50,25
197536 42,84 13,36 ? 47,84 43,28
425364 35,80 91,44 29,03 ? 56,80
1284315 82,66 92,29 89,33 22,66 23,76

I would like to add the columns YTD, AVG and Total (Contract) Value.

The script to crate the view reads as:
CREATE VIEW TurnOver01
(Contract_ID
,TO_Jan00
,TO_Feb00
,TO_Mar00
,TO_...00
,TO_Dec00)
-- ,YTD
-- ,AVG
-- ,Total_Value
AS SELECT Contract_ID
,01.TO_Jan00
,02.TO_Feb00
,03.TO_Mar00
,XX.TO_,,,00
,12.TO_Dec00
-- ,SUM(??????)
-- ,AVG(??????)
-- ,SUM(Tot_Val98+Tot_Val99+Tot_Val00)
FROM Turnover_Jan00 01
LEFT OUTER JOIN Turnover_Feb00 02 ON 01.Contract_ID = 02.Contract_ID
LEFT OUTER JOIN Turnover_Mar00 03 ON 01.Contract_ID = 03.Contract_ID
...
LEFT OUTER JOIN Turnover_Dec00 12 ON 01.Contract_ID = 12.Contract_ID ;

TIA and kind regards.
Karlo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top