Bird
0
0

Identify the error in this query: SELECT COUNT(price), SUM(price) FROM sales WHERE price = NULL;

medium📝 Debug Q6 of 15
PostgreSQL - Aggregate Functions and GROUP BY
Identify the error in this query: SELECT COUNT(price), SUM(price) FROM sales WHERE price = NULL;
AUsing '=' to compare with NULL is incorrect
BCOUNT cannot be used with price column
CSUM cannot be used with price column
DMissing GROUP BY clause
Step-by-Step Solution
Solution:
  1. Step 1: Check NULL comparison

    In SQL, NULL cannot be compared with '='; use IS NULL instead.
  2. Step 2: Validate other parts

    COUNT and SUM can be used on price; GROUP BY is not required here.
  3. Final Answer:

    Using '=' to compare with NULL is incorrect -> Option A
  4. Quick Check:

    NULL comparison needs IS NULL [OK]
Quick Trick: Use IS NULL, not = NULL for NULL checks [OK]
Common Mistakes:
  • Using = NULL instead of IS NULL
  • Assuming GROUP BY needed without aggregation
  • Misusing COUNT or SUM functions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes