﻿ SQL SUBQUERIES: Make a list of all employees who earn more than the average salary and who work in an IT department - w3resource

# SQL Subquery Exercises: Identify all the employees who earn more than the average and who work in any of the IT departments

## SQL SUBQUERY: Exercise-28 with Solution

From the following table, write a SQL query to find out which employees are earning more than the average salary and who work in any of the IT departments. Return last name.

Sample table: employees

Sample table: departments

Sample Solution:

``````SELECT last_name
FROM employees
WHERE department_id IN
(SELECT department_id
FROM departments
WHERE department_name LIKE 'IT%')
AND salary >
(SELECT avg(salary)
FROM employees);
``````

Sample Output:

```last_name
Hunold
```

Pictorial Presentation:

## Query Visualization:

Duration:

Rows:

Cost:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Test your Programming skills with w3resource's quiz.

What is the difficulty level of this exercise?

﻿

## SQL: Tips of the Day

How to count occurrences of a column value in SQL?

Input table:

```id | age
--------
0  | 25
1  | 25
2  | 23
```
```SELECT age, count(age)
FROM Students
GROUP by age
```

Output:

```id | age | count
----------------
0  | 25  | 2
1  | 25  | 2
2  | 23  | 1
```

Ref: https://bit.ly/3zbLPQm