在使用别名的子句中使用子查询

Ram*_*pal 0 mysql sql

我有一个Mysql查询在哪里

我有一张桌子如下(样本数据)

Employee_id Months Salary
  1         10      200
  2         20      300
  3         30      400
Run Code Online (Sandbox Code Playgroud)

现在我想找到拥有最高总工资的员工人数(总工资=月*工资)

所以我有这样的查询

子查询:

((select max(mon_sal.mc) as max_mc from (
  select months*salary as mc from employee group by employee_id) as mon_sal)
as max_mon_sal)
Run Code Online (Sandbox Code Playgroud)

//找到最高工资总额

现在我的问题是我需要找到最高工资的人数,

select max_mon_sal.max_mc,name 
from employee group by employee_id 
having salary=max_mon_sal.max_mc from (
    (select max(mon_sal.mc) as max_mc from 
      (select months*salary as mc from employee group by employee_id) as mon_sal)
    as max_mon_sal)
Run Code Online (Sandbox Code Playgroud)

它显示Error.I有使用max_mon_sal别名的问题.请建议.

sla*_*kso 5

你可以简单地使用:

select count(*)
from employee
where months * salary = (
  select max(months * salary)
  from employee
);
Run Code Online (Sandbox Code Playgroud)