Bird
0
0

You wrote this query to unpivot sales data:

medium📝 Debug Q14 of 15
SQL - Advanced Query Patterns
You wrote this query to unpivot sales data:
SELECT Product, Quarter, Sales FROM SalesData UNPIVOT (Sales FOR Quarter IN (Q1, Q2, Q3)) AS Unpvt;

But it returns an error. What is the likely cause?
AThe FOR clause should be after the IN clause
BUNPIVOT cannot be used with more than two columns
CThe alias 'Unpvt' is missing parentheses
DThe column names in IN clause must be enclosed in square brackets
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax for column names in UNPIVOT

    In SQL Server, column names in the IN list must be enclosed in square brackets if they are identifiers like Q1, Q2, Q3.
  2. Step 2: Identify error cause

    Missing brackets cause syntax error; other options are incorrect syntax rules.
  3. Final Answer:

    The column names in IN clause must be enclosed in square brackets -> Option D
  4. Quick Check:

    Use brackets for column names in UNPIVOT IN list [OK]
Quick Trick: Always bracket column names in UNPIVOT IN list [OK]
Common Mistakes:
  • Omitting brackets around column names
  • Misplacing FOR clause
  • Incorrect alias syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes