function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
adusumalli lakshmiadusumalli lakshmi 

How to write soql to perform aggregate functions on opportunity

Ashif KhanAshif Khan
Hii adusumalli lakshmi

this is sample code of agg Query here you can change your field instead of CampaignId and agg function instead of AVG
AggregateResult[] aggInfo= [SELECT CampaignId, AVG(Amount)  FROM Opportunity GROUP BY CampaignId];
for (AggregateResult ar : aggInfo)  {
    System.debug('Campaign ID' + ar.get('CampaignId'));
    System.debug('Average amount' + ar.get('expr0'));
}

Regards
Ashif