﻿ SQL SUBQUERIES: Determine who earns more than Mr. Ozer - w3resource

# SQL Subquery Exercises: Determine who earns more than Mr. Ozer

## SQL SUBQUERY: Exercise-29 with Solution

From the following table, write a SQL query to find all those employees who earn more than an employee whose last name is 'Ozer'. Sort the result in ascending order by last name. Return first name, last name and salary.

Sample table: employees

Sample Solution:

``````SELECT first_name, last_name, salary
FROM employees
WHERE salary >
(SELECT salary
FROM employees
WHERE last_name='Ozer')
ORDER BY  last_name;
``````

Sample Output:

```first_name	last_name	salary
Lex		De Haan		17000.00
Alberto		Errazuriz	12000.00
Nancy		Greenberg	12000.00
Michael		Hartstein	13000.00
Shelley		Higgins		12000.00
Steven		King		24000.00
Neena		Kochhar		17000.00
Karen		Partners	13500.00
John		Russell		14000.00
```

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