Pandas → T-SQL › pivot
Pandas pivot to SQL PIVOT
Pandas will invent columns from the data. T-SQL PIVOT wants the list in the IN (...).
SELECT customer_id, [Shipped], [Cancelled], [Processing]
FROM (
SELECT customer_id, status, total_amount FROM Orders
) s
PIVOT (SUM(total_amount) FOR status IN ([Shipped], [Cancelled], [Processing])) p;
Unknown statuses: dynamic PIVOT, or see /tools/pivot.
Canonical translation
SELECT customer_id, [Shipped], [Cancelled], [Processing]
FROM (
SELECT customer_id, status, total_amount FROM Orders
) s
PIVOT (SUM(total_amount) FOR status IN ([Shipped], [Cancelled], [Processing])) p;
Then write it on a ticket
Monday is free. A colleague asks, you type, we mark it.
Clock in free