select store.store_code, store.store_name, max(store.avgR)
from (select avg(worker.salary) as avgR, worker.store_code, store.store_name
from worker inner join
store
on worker.store_code = store.store_code
group by worker.store_code
) store
出于某种原因,我得到了错误的代码和具有良好最大平均值的名称。 谁能告诉我,请问这里的问题是什么?感谢。
答案 0 :(得分:0)
如果您希望商店获得最高平均工资,您可以这样做:
select avg(w.salary) as avgR, s.store_code, s.store_name
from worker w inner join
store s
on w.store_code = s.store_code
group by s.store_code, s.store_name
order by avgR desc
limit 1;
注意:
select
中的未聚合列应与group by
匹配。limit
,但我猜测您使用的是MySQL。