
Ultimate access to all questions.
Which of the following SQL keywords can be used to convert a table from a long format to a wide format?
A
TRANSFORM
B
PIVOT
C
SUM
D
CONVERT
E
WHERE
Explanation:
The correct answer is PIVOT.
SELECT *
FROM sales_data
PIVOT (
SUM(amount)
FOR product_category IN ('Electronics', 'Clothing', 'Books')
) AS pivoted_table;
SELECT *
FROM sales_data
PIVOT (
SUM(amount)
FOR product_category IN ('Electronics', 'Clothing', 'Books')
) AS pivoted_table;
This would convert long-format sales data with multiple rows per product category into wide format with separate columns for each product category.