title: How to optimize SQL query with multiple selects
body: <p>I have a query that uses multiple SELECTS, and I need to optimize this but I have no clue how to do this.</p>
  
  <p>Query:</p>
  
  <pre><code>SELECT e.last_name, e.salary, t1.PROMEDIO 
  FROM employees e, 
       (
         SELECT e.department_id, AVG(e.salary) PROMEDIO 
         FROM employees e 
         GROUP  BY e.department_id
       ) t1 
  WHERE e.department_id = t1.department_id 
       AND e.salary &lt; t1.PROMEDIO;
  </code></pre>