The Sales Analysis III interview question asks you to find all products that were sold ONLY in the first quarter of 2019 (January 1 to March 31, 2019). A product qualifies if every sale record for that product falls within this date range — products also sold outside this range must be excluded. This is a "group filter" SQL problem requiring per-product date boundary checking.
Amazon and Bloomberg ask this SQL problem because it tests per-group filtering using HAVING with date aggregates — a pattern essential in business analytics for cohort analysis, seasonal reporting, and date-range compliance checks. It also distinguishes candidates who understand that filtering must happen at the group level (HAVING), not the row level (WHERE).
The pattern is GROUP BY with HAVING on date aggregates. Group sales by product. For each product, check that the minimum sale date is ≥ '2019-01-01' AND the maximum sale date is ≤ '2019-03-31'. This ensures every sale for that product falls within Q1 2019.
SELECT s.product_id, p.product_name
FROM Sales s
JOIN Product p ON s.product_id = p.product_id
GROUP BY s.product_id, p.product_name
HAVING MIN(s.sale_date) >= '2019-01-01'
AND MAX(s.sale_date) <= '2019-03-31';
Sales:
Result: Product 1 only.
MIN/MAX approach: Product 1 MIN=Jan 10, MAX=Feb 15 — both within bounds → include. Product 2 MAX=Apr 1 > Mar 31 → exclude.
sale_date BETWEEN '2019-01-01' AND '2019-03-31' in WHERE — excludes some rows but doesn't prevent products with other-date sales from appearing.For the Sales Analysis III coding problem, the database interview pattern is GROUP BY with HAVING on MIN/MAX aggregates for date-range compliance. The key insight: checking MIN ≥ start AND MAX ≤ end is equivalent to checking ALL dates are in range. Bloomberg interviewers may ask "can you use NOT EXISTS instead?" — yes, but the HAVING approach is more concise. Practice writing HAVING clauses with date arithmetic for seasonal business analytics queries.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Biggest Single Number | Easy | Solve | |
| Sales Person | Easy | Solve | |
| Ad-Free Sessions | Easy | Solve | |
| All Valid Triplets That Can Represent a Country | Easy | Solve | |
| Consecutive Available Seats | Easy | Solve |