Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Desafío de Empleados con un Salario Superior al Promedio | Subconsultas Anidadas
SQL Intermedio

book
Desafío de Empleados con un Salario Superior al Promedio

When a subquery is written in the WHERE section, we can use the IN operator and comparison operators:

Mencioné anteriormente que cuando una subconsulta se escribe en la sección WHERE, podemos utilizar el operador IN y los operadores de comparación.

Por ejemplo, así:

Tarea

Swipe to start coding

Find employees whose salary is above the average salary of all employees using a subquery in the WHERE section.

The resulting table should have 3 columns: first_name, last_name, and salary. Then, sort the result by salary from highest to lowest using ORDER BY.

Note

This syntax can be used as a great alternative to the HAVING clause.

Brief Instructions

  • Retrieve the first_name, last_name, and salary columns from the employees table.
  • In the WHERE clause, use an inner query with the syntax salary > [inner query].
  • In the inner query, get the average value of the salary column from the employees table.
  • Sort the results by salary in descending order.

Solución

SELECT first_name, last_name, salary
FROM employees
WHERE salary > (SELECT AVG(salary) FROM employees)
ORDER BY salary DESC;
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 4

toggle bottom row
Query ResultQuery Result
No query executed yet...
some-alt