Answer the following SQL tasks of increasing difficulty:
-
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.
-
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.
-
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.