Now in full Beta 2
BuyCTB
Contrib

How to use user variable as counter with inner join queries that contains GROUP BY statement?

Sign in to vote

I have 2 tables odds and matches : matches : has match_id and match_date odds : has id, timestamp, result, odd_value, user_id, match_id I had a query that get the following information from those tables for each user: winnings : the winning bets for each user. (when odds.result = 1) loses : the lost bets for each user.(when odds.result != 1) points : the points of each user.(the sum of the odds.odd_value) for each user. bonus : for each continuous 5 winnings i want to add extra bonus to this variable. (for each user) How to calculate bonus? I tried to use this query and I faced a problem : (you can check it here SQL Fiddle) the calculated bonus are not right for all the users : first user:(winnings:13, bonus=2). second user:(winnings:8, bonus=2)bonus here should be 1. third user:(winnings:14, bonus=3)bonus here should be 2. why does the query not calculate the bonus correctly?

Sign in to join the discussion.

No comments yet. Be the first to reply.