Bird
0
0

Given the table orders with 5 rows where the discount column has values: 10, NULL, 5, NULL, 0, what will be the result of SELECT COUNT(*) AS total, COUNT(discount) AS discount_count FROM orders;?

medium📝 query result Q13 of 15
SQL - Aggregate Functions
Given the table orders with 5 rows where the discount column has values: 10, NULL, 5, NULL, 0, what will be the result of SELECT COUNT(*) AS total, COUNT(discount) AS discount_count FROM orders;?
Atotal = 5, discount_count = 3
Btotal = 5, discount_count = 5
Ctotal = 3, discount_count = 3
Dtotal = 3, discount_count = 5
Step-by-Step Solution
Solution:
  1. Step 1: Count total rows with COUNT(*)

    COUNT(*) counts all 5 rows regardless of NULLs.
  2. Step 2: Count non-NULL discount values with COUNT(discount)

    Only 3 rows have non-NULL discount values (10, 5, 0), so discount_count is 3.
  3. Final Answer:

    total = 5, discount_count = 3 -> Option A
  4. Quick Check:

    COUNT(*) = all rows, COUNT(column) = non-NULL rows [OK]
Quick Trick: COUNT(*) counts all rows; COUNT(column) skips NULLs [OK]
Common Mistakes:
MISTAKES
  • Counting NULLs in COUNT(column)
  • Confusing total rows with non-NULL counts
  • Assuming 0 is NULL

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes