Bird
0
0

Find the issue in this query: SELECT AVG(salary) FROM employees WHERE salary != NULL;

medium📝 Debug Q7 of 15
SQL - Aggregate Functions
Find the issue in this query: SELECT AVG(salary) FROM employees WHERE salary != NULL;
AMissing GROUP BY clause causes error
BAVG cannot be used with WHERE clause
CComparison with NULL using != is invalid, use IS NOT NULL
DNo issue, query is correct
Step-by-Step Solution
Solution:
  1. Step 1: Understand NULL comparison in WHERE

    Comparing with NULL using != or = is invalid; use IS NOT NULL instead.
  2. Step 2: Correct the WHERE clause

    Use WHERE salary IS NOT NULL to filter out NULLs properly.
  3. Final Answer:

    Comparison with NULL using != is invalid, use IS NOT NULL -> Option C
  4. Quick Check:

    Use IS NOT NULL to filter NULLs, not != NULL = A [OK]
Quick Trick: Use IS NOT NULL to check for non-NULL values in WHERE [OK]
Common Mistakes:
MISTAKES
  • Using != NULL instead of IS NOT NULL
  • Assuming AVG disallows WHERE
  • Confusing GROUP BY necessity

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes