Jeg er ikke sikker på, hvordan dit resultat relaterer sig til matches
tabel,
du kan tilføje tilbage WHERE
/ INNER JOIN
klausul, hvis du har brug for det.
Her er link til violin
og den sidste iteration ifølge dine kommentarer:
Og her er en forespørgsel:
SET @user:=0;
select d.user_id,
sum(case when d.result = 1 then 1 else 0 end) as winnings,
sum(case when d.result = 2 then 1 else 0 end) as loses,
sum(case when d.result = 1 then d.odd_value else 0 end) as points,
f.bonus
FROM odds d
INNER JOIN
(
SELECT
user_id,SUM(bonus) AS bonus
FROM
(
SELECT
user_id,
CASE WHEN result=1 and @counter<5 AND @user=user_id THEN @counter:[email protected]+1
WHEN result=1 and @counter=5 AND @user=user_id THEN @counter:=1
WHEN result=1 and @user<>user_id THEN @counter:=1
ELSE
@counter:=0
END AS F1,
@user:=user_id,
CASE WHEN @counter=5 THEN 1 ELSE 0 END AS bonus
FROM odds o
ORDER BY user_id , match_id
) Temp
group by user_id
)as f on f.user_id = d.user_id
group by d.user_id