Ik weet niet zeker hoe je resultaat zich verhoudt tot matches
tafel,
je kunt terug WHERE
. toevoegen / INNER JOIN
clausule als je nodig hebt.
Hier is link naar fiddle
en de laatste iteratie volgens uw opmerkingen:
En hier is een vraag:
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