RienSQL
TASK #171 · Hard · Entain

Weekly Bet Dynamics (LAG)

Your brief
For every player and every week (Monday is the week start) in which the player placed at least one bet, output:
  • customer_id
  • week_start_date — the Monday of that week
  • avg_bet_amount — average bet for that week (rounded to two decimals)
  • prev_week_total — the player's total bet amount in their previous active week (via the window function LAG() over SUM(bet_amount), ordered by week_start_date). For the player's first week prev_week_total is NULL.
Sort by customer_id, then by week_start_date.
Expected columnscustomer_id week_start_date avg_bet_amount prev_week_totalEntain / Bwin
SQL editor
SQLite
Ctrl / ⌘ + ↵
Result

Write a query and run it to see the results.

Schema
customerscustomer_id, name, country, active
gamesgame_id, name, game_category
betsbet_id, customer_id, game_id, bet_date, bet_amount, betting_type
winswin_id, customer_id, win_date, win_amount