Complete the code to select the year column from the sales table.
SELECT [1] FROM sales;The year column contains the year data we want to select from the sales table.
Complete the code to pivot the sales data by year using SUM of amount.
SELECT * FROM sales PIVOT (SUM(amount) FOR [1] IN (2019, 2020, 2021));
The year column is used to pivot the sales data by year.
Fix the error in the UNPIVOT clause by completing the missing column name.
SELECT year, category, amount FROM sales UNPIVOT (amount FOR [1] IN (Q1, Q2, Q3, Q4));The quarter column is used to unpivot the quarterly sales data into rows.
Fill both blanks to create a pivot table showing total sales by category for each year.
SELECT category, [1] FROM sales PIVOT (SUM(amount) FOR [2] IN (2019, 2020, 2021));
The years 2019, 2020, and 2021 are the columns created by pivoting on the year column.
Fill all three blanks to unpivot quarterly sales data into a long format with columns quarter and amount.
SELECT year, category, [1], [2] FROM sales UNPIVOT ([3] FOR quarter IN (Q1, Q2, Q3, Q4));
The unpivoted columns are quarter and amount. The FOR clause uses 'quarter' and the unpivoted value is 'amount'.