How to find maximum avg

前端 未结 15 2269
长情又很酷
长情又很酷 2020-12-15 19:17

I am trying to display the maximum average salary; however, I can\'t seem to get it to work.

I can get a list of the average salaries to display with:



        
15条回答
  •  余生分开走
    2020-12-15 20:22

    You can fix the query by adding a column alias to the column within the sub-query, like so:

    select max(avg_salary)
    from (select worker_id, avg(salary) avg_salary
          from workers
          group by worker_id);
    

    However, if worker_id uniquely identifies records on the workers table, this is functionally equivalent to (can be simplified to):

    select max(salary) from workers;
    

提交回复
热议问题