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!

Sum over all groups

Status
Not open for further replies.

glschill

MIS
Aug 29, 2001
6
US
If I have a query grouped by a certain field, is there a quick way to display the sum of each field and also the total sum of all the groups like in the following example. I know how to get the group sum, but it's the SumOverAll that I'm not sure how to get. I need that in order to calculate a percentage of the overall total.

Example:
Select Field, Sum(Value) as GroupSum
From Table
Group By Field

Field GroupSum SumOverAll %OfTotal
Item1 100 600 16.67
Item2 200 600 33.33
Item3 300 600 50.00
 
You need to join the grouped queries

Select Field, GroupSum, SumOverAll, decode(SumOverAll, 100,GroupSum/SumOverAll*100)
From
(select field, Sum(Value) GroupSum
from Table
Group By Field) a,
(select sum(value) SumOverAll from Table) b

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top