Given a table of user betting logs, write a query to identify consecutive losing streaks exceeding a specific threshold for risk assessment.
Assume the threshold is more than 3 consecutive losing bets. A win or a missing result ends the current losing streak.
user_id, streak_start, streak_end, and losing_bets.user_id, then streak_start, then streak_end.loss, including NULL, as ending the current losing streak.bet_timestamp ascending, breaking timestamp ties with bet_id ascending.user_id, streak_start, and streak_end in ascending order.streak_start and streak_end to the earliest and latest bet_timestamp values in each streak.| Column | Type | Description |
|---|---|---|
| bet_idPK | INT | Unique identifier for the bet |
| user_id | INT | Identifier of the bet365 user |
| bet_timestamp | TIMESTAMP | Time when the bet was settled |
| outcome | VARCHAR(20) | Bet result, such as loss, win, or void |
| stake | NUMERIC(10,2) | Amount staked on the bet |