Interview › Window vs GROUP BY
SQL interview: why the table did not shrink
If they still want the order_id and a total, they want a window, not a GROUP BY.
Prompt. Show each order and the customer’s total spend on the same row.
Hint: SUM(total_amount) OVER (PARTITION BY customer_id)
SELECT order_id, customer_id, total_amount,
SUM(total_amount) OVER (PARTITION BY customer_id) AS customer_sales
FROM Orders;
GROUP BY customer_id cannot keep order_id unless you aggregate it. That is Msg 8120.
Then write it on a ticket
Monday is free. A colleague asks, you type, we mark it.
Clock in free