Bird
0
0

Given the table sales with column amount containing values (100, 200, NULL, 300), what is the result of this query?

medium📝 query result Q13 of 15
PostgreSQL - Aggregate Functions and GROUP BY
Given the table sales with column amount containing values (100, 200, NULL, 300), what is the result of this query?
SELECT COUNT(amount), SUM(amount), AVG(amount), MIN(amount), MAX(amount) FROM sales;
A(4, 600, 150, 100, 300)
B(4, 600, 200, 100, 300)
C(3, 600, 150, 100, 300)
D(3, 600, 200, 100, 300)
Step-by-Step Solution
Solution:
  1. Step 1: Count non-null values in amount

    Values are 100, 200, NULL, 300. COUNT(amount) counts non-null values = 3.
  2. Step 2: Calculate SUM, AVG, MIN, MAX ignoring NULL

    SUM = 100+200+300 = 600; AVG = 600/3 = 200; MIN = 100; MAX = 300.
  3. Final Answer:

    (3, 600, 200, 100, 300) -> Option D
  4. Quick Check:

    COUNT=3, SUM=600, AVG=200 [OK]
Quick Trick: Aggregate functions ignore NULL except COUNT(*) [OK]
Common Mistakes:
  • Counting NULL as a value in COUNT(column)
  • Dividing AVG by total rows including NULL
  • Confusing COUNT(column) with COUNT(*)

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes