You use a Microsoft SQL Server database that contains a table. The table has records of customer orders.
Your company has three divisions that have the following names:
- East
- Central
- West
You need to create a query that displays the following information:
- The number of sales for each product (ProductName) grouped by the division (Division) that sold the product
- A column for each division
Which Transact-SQL query should you use?
A. Option A
B. Option B
C. Option C
D. Option D
You can use the PIVOT and UNPIVOT relational operators to change a table-valued expression into another table. PIVOT rotates a table-valued expression by turning the unique values from one column in the expression into multiple columns in the output, and performs aggregations where they are required on any remaining column values that are wanted in the final output. UNPIVOT performs the opposite operation to PIVOT by rotating columns of a table-valued expression into column values.
References: https://technet.microsoft.com/en-us/library/ms177410(v=sql.105).aspx