All jobs / Data analyst / BI / SQL
Data analyst / BI interview question · 0–1 years
SELECT customer_id, SUM(amount) without GROUP BY — what is wrong?
The strongest answer
The grain is mixed — an aggregate next to a raw key is either an error or a hidden window; I group or I window on purpose
Why it works
Exactly. Aggregates need a grain. Old engines that guessed a group are not a standard.
What a good answer covers
- Aggregates need GROUP BY or a window.
- Name the grain.
- Do not rely on old dialects.
- ORDER BY is not a group.
Answers that fall short
- Close, but not the strongest: Nothing on MySQL in 2008, so it is a style issue
A historical dialect is not a reason. - Weak: SUM without GROUP BY always returns one row, so it is safe
One row may be what you wanted — then say so and drop the raw key. - Red flag: I add ORDER BY to fix it
ORDER BY does not group.
Who gets asked this
More SQL questions
- You LEFT JOIN orders, then WHERE orders.status = 'paid'. What did you just do?
- You need each order and the customer’s lifetime total on the same row. What do you use?
- 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?