TASK #170 · Medium · EntainAverage Bet and Total Wins per Active Player
Your brief
For every active player (customers.active = true)
output customer_name, avg_bet — that player's
average bet size (rounded to two decimals) — and total_wins
— their total win amount. If the player has no wins yet, return
0, not NULL.
Beware: a naive
Sort by customer_name.
Beware: a naive
JOIN bets × wins on customer_id
yields a Cartesian product per player and corrupts both
aggregations. Compute averages and sums separately, then join the
already-aggregated results.
Sort by customer_name.
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