Pivot Sales Category Rows Into Columns
How do I pivot rows into columns in SQL Server?
sql
SELECT * FROM ( SELECT category, amount FROM sales ) AS SourceTable PIVOT ( SUM(amount) FOR category IN ([Electronics], [Clothing], [Home]) ) AS PivotTable;
This query uses the PIVOT operator to transform unique values from the "category" column into individual columns, aggregating the "amount" values using the SUM function.
PromptDB can make mistakes. Please double-check responses.