Bird
0
0

Which aggregate function combined with CASE can count only rows where a column status equals 'completed'?

easy📝 Conceptual Q2 of 15
SQL - CASE Expressions
Which aggregate function combined with CASE can count only rows where a column status equals 'completed'?
AMAX(CASE WHEN status = 'completed' THEN 1 ELSE 0 END)
BSUM(CASE WHEN status = 'completed' THEN 1 ELSE 0 END)
CAVG(CASE WHEN status = 'completed' THEN 1 ELSE 0 END)
DMIN(CASE WHEN status = 'completed' THEN 1 ELSE 0 END)
Step-by-Step Solution
Solution:
  1. Step 1: Identify how to count conditionally

    Counting rows with a condition is done by summing 1 for matching rows and 0 otherwise.
  2. Step 2: Match aggregate function to counting logic

    SUM adds up the 1s, effectively counting rows where status = 'completed'.
  3. Final Answer:

    SUM(CASE WHEN status = 'completed' THEN 1 ELSE 0 END) -> Option B
  4. Quick Check:

    SUM + CASE = Conditional count [OK]
Quick Trick: Use SUM with CASE to count conditionally [OK]
Common Mistakes:
  • Using AVG which averages values, not counts
  • Using MAX or MIN which find extremes, not counts
  • Forgetting ELSE 0 in CASE

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes