Interview › Pivot
SQL interview: rows to columns (PIVOT / CASE)
Wide reports are either PIVOT or a handful of SUM(CASE). Interviewers accept both. CASE is easier to read.
Prompt. One row per customer, columns for Shipped, Cancelled, Processing sales.
Hint: SUM(CASE WHEN status = … THEN amount ELSE 0 END)
SELECT customer_id,
SUM(CASE WHEN status = 'Shipped' THEN total_amount ELSE 0 END) AS shipped,
SUM(CASE WHEN status = 'Cancelled' THEN total_amount ELSE 0 END) AS cancelled,
SUM(CASE WHEN status = 'Processing' THEN total_amount ELSE 0 END) AS processing
FROM Orders
GROUP BY customer_id;
Dynamic statuses: /tools/pivot. Do not concatenate user text into PIVOT IN.
Then write it on a ticket
Monday is free. A colleague asks, you type, we mark it.
Clock in free