在Oracle中,可以使用PIVOT和UNPIVOT命令来实现行列转换。
SELECT *
FROM (
SELECT product_type, sales_amount
FROM sales_data
)
PIVOT
(
SUM(sales_amount)
FOR product_type IN ('A' AS A_sales, 'B' AS B_sales, 'C' AS C_sales)
);
SELECT product_type, sales_amount
FROM (
SELECT A_sales, B_sales, C_sales
FROM sales_data
)
UNPIVOT
(
sales_amount FOR product_type IN (A_sales AS 'A', B_sales AS 'B', C_sales AS 'C')
);
通过PIVOT和UNPIVOT命令,可以实现行列转换的需求。