TASK #171 · Hard · EntainWeekly 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()overSUM(bet_amount), ordered byweek_start_date). For the player's first week prev_week_total isNULL.
Ctrl / ⌘ + ↵
Result
Write a query and run it to see the results.
Schema
customerscustomer_id, name, country, activegamesgame_id, name, game_categorybetsbet_id, customer_id, game_id, bet_date, bet_amount, betting_typewinswin_id, customer_id, win_date, win_amount