You are on page 1of 1

Aggregate Result :

1.
public class AggWrapper {
public String stageName {Set;get;}
public Decimal avgValue {Set;get;}
public Decimal sumValue {set;get;}
}
2.public class AggregateExample {
public List<AggWrapper> resultList {set;get;}
public Decimal maxVal {set;get;}
public Decimal minval {set;get;}
public AggregateExample(){
resultList=new List<AggWrapper>();
List<AggregateResult> result=[select stageName,avg(amount)avgAmt , Sum(am
ount)total from Opportunity group by StageName];
for(AggregateResult rs:result){
AggWrapper aw=new AggWrapper();
aw.stageName=(String)rs.get('stageName');
aw.avgValue=(Decimal)rs.get('avgAmt');
aw.sumValue=(Decimal)rs.get('total');
resultList.add(aw);
}
}
}
<apex:page controller="AggregateExample" contentType="vnd.ms-excel#reporting.xls
" >
<apex:pageBlock title="Result">
<apex:pageBlockTable value="{!resultList}" var="a">
<apex:column value="{!a.stageName}" headerValue="StageName" />
<apex:column value="{!a.avgValue}" headerValue="Average"/>
<apex:column value="{!a.sumValue}" headerValue="Sum Value"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>

You might also like