I can run this query to get a set of n average values:
select avg(r.cat_experience_pro) as avg_exp
from review as r
inner join provider_plan as pp on r.provider_plan_id = pp.provider_plan_id
inner join provider as p on pp.provider_id = p.provider_id
group by p.provider_id
However, what I need is the average of those averages. I tried this:
select avg(
select avg(r.cat_experience_pro) as avg_exp
from review as r
inner join provider_plan as pp on r.provider_plan_id = pp.provider_plan_id
inner join provider as p on pp.provider_id = p.provider_id
group by p.provider_id
)
That, unfortunately, is not allowed, returning an error that a subquery being used as an expression returned more than one value.
The two immediate work-arounds I see are either to dump the result into a temp table against which I could then run a 2nd query to get the average of averages, or to do the "outer" average on the PHP side. Any of you SQL gurus have an alternative, or a preference for either of those work-arounds?