title: using average with group by in mysql
body: <p>I have three table</p>
  
  <pre><code>EMPLOYEE table with ID and NAME
  COMPANY table with ID and NAME
  and 
  SALARY table with EMPLOYEE_ID, COMPANY_ID and SALARY
  </code></pre>
  
  <p>I wanted to print the name of every company where the average salary is greater than or equal to 40000</p>
  
  <p>My query is </p>
  
  <pre><code>Select distinct COMPANY.NAME from COMPANY,SALARY,EMPLOYEE WHERE SALARY.COMPANY_ID=COMPANY.ID and (select avg(SALARY) from SALARY,EMPLOYEE WHERE SALARY.EMPLOYEE_ID=EMPLOYEE.ID) &gt;=40000;
  </code></pre>