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'));
}
this is sample code of agg Query here you can change your field instead of CampaignId and agg function instead of AVG
Regards
Ashif