title: Using Subquery in having clause using alias
body: <p>I have a Mysql Query where </p>
  
  <p>Where i have a table as like below(Sample data)</p>
  
  <pre><code>Employee_id Months Salary
    1         10      200
    2         20      300
    3         30      400
  </code></pre>
  
  <p>Now i wanted to find the Number of Employees who are having the  Maximum total salary
  (Total salary =month * salary)</p>
  
  <p>So i have my query like this</p>
  
  <p>Subquery:</p>
  
  <pre><code>((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)
  </code></pre>
  
  <p>//To find the Maximum of Total salary </p>
  
  <p>Now my problem is i need to find the number of persons having the maximum salary,</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>Its showing Error.I have problem with using the max_mon_sal alias.Please suggest.</p>