Solve three SQL problems (easy/medium/hard)
Company: OPPO
Role: Data Engineer
Category: Data Manipulation (SQL/Python)
Difficulty: Medium
Interview Round: Technical Screen
Answer the following SQL tasks of increasing difficulty:
1) Aggregation: Given Orders(order_id, customer_id, amount, order_date), return each customer's total spend and order count for Jan 1–Dec 31, 2024, sorted by total spend descending.
2) Windowing: Given Transactions(id, user_id, amount, created_at), compute for each user the 7-day rolling sum of amount for every calendar date present in the data, emitting dates with zero activity where needed.
3) Advanced joins and gaps-islands: Given Sessions(user_id, start_time, end_time) and Memberships(user_id, plan, activated_at, canceled_at), find users who had any session time while their membership was inactive (outside [activated_at, canceled_at)), and output user_id and total inactive-session minutes.
Quick Answer: This question evaluates proficiency in SQL data manipulation including aggregation, window functions for rolling calculations, temporal joins, and gaps-and-islands analysis across increasing difficulty levels.