SQL data engineering interview problem. Difficulty: intermediate. Pattern: Window Functions. About 12 minutes. Part of the Pro drill bank.
For each lb_orders row, compute a running total of amount per customer_id ordered by order_date, then order_id. Columns: customer_id, order_date, amount, running_total. Order by customer_id, order_date, order_id.
Input: lb_orders customer_id | order_date | amount | order_id C01 | 2024-01-05 | 1200 | 1 C01 | 2024-02-08 | 35 | 2 C01 | 2024-03-12 | 40 | 3 Output: customer_id | order_date | amount | running_total C01 | 2024-01-05 | 1200 | 1200 C01 | 2024-02-08 | 35 | 1235 C01 | 2024-03-12 | 40 | 1275 Why this passes: The window sum accumulates in date order within the customer partition.
Topics: lakebench, sql, running total, sum window.
More SQL interview questions · All interview problems · Learn data engineering
Interview-style drill: Running sum of order amounts per customer ordered by date.
For each `lb_orders` row, compute a running total of `amount` per `customer_id` ordered by `order_date`, then `order_id`. Columns: `customer_id`, `order_date`, `amount`, `running_total`. Order by `customer_id`, `order_date`, `order_id`.