Bird
0
0

Given the table orders with columns category and amount, what does this query return?

medium📝 query result Q4 of 15
SQL - CASE Expressions
Given the table orders with columns category and amount, what does this query return?
SELECT category, SUM(CASE WHEN amount > 100 THEN 1 ELSE 0 END) AS big_orders FROM orders GROUP BY category;
ATotal amount of orders per category where amount is greater than 100
BNumber of orders per category regardless of amount
CNumber of orders per category where amount is greater than 100
DSum of all amounts per category
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the CASE inside SUM

    CASE returns 1 if amount > 100, else 0, so SUM counts how many orders exceed 100 per category.
  2. Step 2: Understand GROUP BY effect

    Grouping by category aggregates counts per category, showing number of big orders per category.
  3. Final Answer:

    Number of orders per category where amount is greater than 100 -> Option C
  4. Quick Check:

    SUM(CASE) counts condition per group [OK]
Quick Trick: SUM(CASE) counts condition per group [OK]
Common Mistakes:
  • Thinking SUM returns total amount instead of count
  • Ignoring GROUP BY effect
  • Confusing ELSE 0 with NULL

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes