I have some data of people betting. The bets can be 'won', 'lost' or 'pending'. I want to get the amount people have bet and the amount they have won.
The amount won should be amount * odds BUT if it was a bonus bet (1) it will subtract the original stake (amount) from the total. Bonus bets do not include the original stake in the total win amount.
Also amountbet should not include the amount from Bonus bets as they are more tokens then lost money. Hopefully in one SQL.
I have got this far....
SELECT *, SUM(amount) AS amountbet
FROM bets
WHERE club = 2
AND result <> 'pending'
AND bonus = 0
GROUP BY user
And I also have this SQL statement
SELECT *, SUM(amount * odds - (amount * bonus)) AS amountwon
FROM bets
WHERE club = 2
AND result = 'won'
GROUP BY user
So if it is a bonus bet it will subtract amount or it will subtract amount * 0 i.e. = 0
I can probably work around if not but if there is an elegant way I would like to try.
Thanks
The DB table looks like this
ID | user | amount | odds | result | bonus | club |