SQL · Question 8 · Medium

SQL question 8

Table Employee:
id | name | dept | salary
1 | Asha | HR | 30000
2 | Ravi | IT | 50000
3 | Neha | IT | 60000
4 | Karan | Sales | NULL
5 | Priya | HR | 45000
6 | Vikram | IT | 50000

Which names does this query return?

SELECT name
FROM Employee
WHERE salary > (SELECT AVG(salary) FROM Employee);
  1. Neha only
  2. Ravi, Neha, Vikram and Priya
  3. Ravi and Neha
  4. Ravi, Neha and Vikram
Answer and explanation

Answer: D. Ravi, Neha and Vikram

Explanation: AVG ignores NULL: (30000 + 50000 + 60000 + 45000 + 50000) / 5 = 47000. The employees earning more than 47000 are Ravi, Neha and Vikram. Karan's NULL salary fails the comparison.

Previous: Table Employee: id | name | dept | salary 1 | Asha | HR | 30000 2 | Ravi | IT… · Next: Using a table Employee(id, name, dept, salary), which of the following queries…

Practise sql

Try a fresh set of sql questions with an explanation after every answer, free and without signing up: SQL practice. Or sit a full placement mock test.

More sql questions

More technical & programming practice

Operating Systems · Computer Networks · Software Engineering · Cloud & DevOps · GenAI Basics · Pseudo-code · C Programming · Java

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge