This question evaluates a candidate's ability to perform data aggregation, filtering, ranking, and deterministic tie-breaking on transactional datasets, assessing skills in Data Manipulation (SQL/Python).
transactions
+----+---------+------------+--------+ | id | user_id | order_date | amount | +----+---------+------------+--------+ | 1 | 101 | 2023-01-01 | 120.50 | | 2 | 102 | 2023-01-08 | 75.00 | | 3 | 101 | 2023-02-02 | 200.00 | | 4 | 103 | 2023-02-10 | 40.00 | | 5 | 104 | 2023-03-12 | 150.00 | +----+---------+------------+--------+
Retail promotion targeting based on historical transaction data.
Given a transactions table, select the customers who satisfy the provided campaign filters.
From those customers select exactly five with the highest total order count.
Explain how you would break ties if more than five customers meet the top-5 criterion.
Aggregate by customer, ORDER BY order_cnt DESC, LIMIT 5; add secondary sort (e.g., most recent order date or random) for deterministic tie-breaking.