Interview › Percent of total

SQL interview: share of total with a window

The total is one window. The row stays. That is SUM() OVER () with an empty PARTITION.

Prompt. Each order as a percent of that customer’s spend, and of all spend.

Hint: SUM(total_amount) OVER (PARTITION BY customer_id)

Times 1.0 (or CAST to decimal) or you get integer 0. NULLIF the total if it can be 0.

Then write it on a ticket

Monday is free. A colleague asks, you type, we mark it.

Clock in free