Bird
0
0

Consider this query:

medium📝 query result Q5 of 15
SQL - Advanced Query Patterns
Consider this query:
SELECT * FROM Sales PIVOT (SUM(Amount) FOR Month IN ('Jan', 'Feb', 'Mar')) AS p;

What will this query do?
AUnpivot the Month columns into rows.
BCreate columns Jan, Feb, Mar with summed Amounts for each group.
CReturn an error because Month values are strings and need casting.
DFilter rows where Month is Jan, Feb, or Mar.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze PIVOT usage

    PIVOT aggregates Amount by Month, creating columns for Jan, Feb, Mar.
  2. Step 2: Check options

    Create columns Jan, Feb, Mar with summed Amounts for each group. correctly describes the result. Others describe errors or wrong operations.
  3. Final Answer:

    Create columns Jan, Feb, Mar with summed Amounts for each group. -> Option B
  4. Quick Check:

    PIVOT creates columns with aggregates [OK]
Quick Trick: PIVOT sums values into new columns [OK]
Common Mistakes:
  • Confusing PIVOT with UNPIVOT
  • Thinking string literals cause errors
  • Assuming filtering happens

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes