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)

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