SOQL Scenario- 5

Aggregate functions

public class SoqlQuery5 {
    public list<Account> acc{set;get;}
    public Integer count{set;get;}
    public Decimal summ{set;get;}
    Public decimal ttal{set;get;}
    public Decimal mm{set;get;}
    public Decimal mn{set;get;}
    public SoqlQuery5(){
        acc=[select Id, name, phone from account where name='s' limit 5];
        count=[select count() from Account where name='s' ];
        Aggregateresult result=[select sum(AnnualRevenue) amt, Avg(AnnualRevenue) total, Min(AnnualRevenue) minm, Max(AnnualRevenue) maxm from Account];
        summ=(Decimal)result.get('amt');
        ttal=(decimal)result.get('total');
        mm=(Decimal)result.get('minm');
        mn=(Decimal)result.get('maxm');
    }  
}

<apex:page controller="SoqlQuery5">
    <apex:form >
    <apex:pageBlock >
        <apex:pageBlockTable value="{!acc}" var="a">
            <apex:column headerValue="Name" value="{!a.name}" />
                <apex:column headerValue="phone" value="{!a.phone}" />
            </apex:pageBlockTable>
            <apex:pageBlocksection>
            Total No of Accounts<apex:outputText>{!count}</apex:outputText>
            Sum Of the Amount   <apex:outputText>{!summ}</apex:outputText>
            Average of Amount <apex:outputText>{!ttal}</apex:outputText>
            Minimum <apex:outputText>{!mm}</apex:outputText>
            Max <apex:outputText>{!mn}</apex:outputText>
            </apex:pageBlocksection>
        </apex:pageBlock>
    </apex:form>
</apex:page>


Comments

Popular posts from this blog

Page Layouts

SOQL Scenario-1