Trigger to perform average or sum of child records on parent object based on product type

Job ID: 34154376

Budget: ₹100 – ₹400 INR

Hi there.. I need help with a trigger which averages sub opportunities revenue field when product type is same else it sums the revenues at the parent (opprtunity object).
The trigger which I have written below only sums. Please help me so that based on the similar product types the revenue gets averages else sumed up.
Related categories: Salesforce App Development