Employees With More Than Average Salary Challenge
I mentioned earlier that when a subquery is written in the WHERE
section, we can use the IN
operator and comparison operators
.
For example, like this:
Following a similar algorithm, you'll need to complete the following task.
We'll be working with the employees
table, which looks like this:
employee_id | first_name | last_name | department | salary | hire_date |
---|---|---|---|---|---|
1 | John | Doe | Engineering | 80000.00 | 2015-03-01T00:00:00Z |
2 | Jane | Smith | Engineering | 90000.00 | 2017-08-15T00:00:00Z |
3 | Alice | Johnson | Marketing | 75000.00 | 2016-11-10T00:00:00Z |
4 | Bob | Brown | Marketing | 72000.00 | 2018-06-25T00:00:00Z |
... | ... | ... | ... | ... | ... |
100 | William | Solis | Sales | 55000.00 | 2020-05-01T00:00:00Z |
Завдання
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.
Все було зрозуміло?
Зміст курсу
Розширений рівень SQL
Розширений рівень SQL
Employees With More Than Average Salary Challenge
I mentioned earlier that when a subquery is written in the WHERE
section, we can use the IN
operator and comparison operators
.
For example, like this:
Following a similar algorithm, you'll need to complete the following task.
We'll be working with the employees
table, which looks like this:
employee_id | first_name | last_name | department | salary | hire_date |
---|---|---|---|---|---|
1 | John | Doe | Engineering | 80000.00 | 2015-03-01T00:00:00Z |
2 | Jane | Smith | Engineering | 90000.00 | 2017-08-15T00:00:00Z |
3 | Alice | Johnson | Marketing | 75000.00 | 2016-11-10T00:00:00Z |
4 | Bob | Brown | Marketing | 72000.00 | 2018-06-25T00:00:00Z |
... | ... | ... | ... | ... | ... |
100 | William | Solis | Sales | 55000.00 | 2020-05-01T00:00:00Z |
Завдання
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.
Все було зрозуміло?