All jobs / Data analyst / BI / SQL
Data analyst / BI interview question · 1–3 years
You need each order and the customer’s lifetime total on the same row. What do you use?
The strongest answer
A window sum partitioned by customer — I do not join the table to an aggregate of itself if a window is clearer, and I do not GROUP BY and lose the order grain
Why it works
Exactly. Windows keep the grain and add a measure. GROUP BY collapses it.
What a good answer covers
- Window to keep the row grain.
- GROUP BY collapses.
- Do not hope dialects keep extras.
- Spreadsheets are not the join.
Answers that fall short
- Close, but not the strongest: GROUP BY customer_id only, and hope the order columns survive
Ungrouped columns are a dialect accident. - Weak: A spreadsheet after export
Excel is not the engine. - Red flag: A correlated subquery in the SELECT list for every row, as a style
A correlated subquery can work and still be the slower way to say window.
Who gets asked this
More SQL questions
- You join orders to refunds (many refunds per order) then average order value. What bites you?
- A customer dimension has two rows per person after an address change. How do you join a fact?
- A “helpful” dashboard takes a raw table name from a query string. What do you say?
- You want each user’s first paid order date next to every order. How?
- A query that was fine on a sample scans the lake for 20 minutes in prod. What do you look at?
- A popular dashboard scans a year of raw events every open. What do you do?
- A junior’s query is correct and unreadable. How do you review?
- You need “the plan the customer was on when they churned.” What join?