Practice mode DBMS and SQL

Table Emp(id, dept, salary) has rows (1,’HR’,3000), (2,’IT’,5000), (3,’IT’,4000), (4,’HR’,NULL), (5,’Ops’,2000). SELECT AVG(salary) FROM Emp WHERE dept = ‘HR’; What value is returned?

Correct answer D. 3000

Explanation

The WHERE clause keeps two HR rows, salaries 3000 and NULL. AVG ignores NULL inputs, so it averages only the single non-null value and returns 3000. Answering 1500 assumes the NULL is treated as zero and divided over two rows. If you want NULL counted as zero, write AVG(COALESCE(salary, 0)) explicitly.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.