I am trying to calculate the weighted average and have used the below query.
select di.name, count(di.name) ,dmic.c_name, sum(count(di.name)*dmic.c_price)/count(di.name) as avgPrice from di join.. on.. join.. on.. where... group by 1,3 order by 2 desc;
And I am getting the error: aggregate function calls may not have nested aggregate or window function. How can I work around this? I am looking to get the name, its occurrences and its weighted price in the output.