I'm developing a query on phpmyadmin mysql in which I intend to display the running balance of a column say 'CurrentBalance'
The running balance of this column depends when the Activity is a deposit (+), a withdraw (-) , bet (-), payout (+)
What I come up is this
SELECT CONCAT("Trans ID ",`TransactionID`) AS ID,
`DateTime`,`Type` AS Activity, `Amount`, 0 AS Payout,
CASE WHEN (SELECT Activity) = "deposit" THEN `Amount`+ `playerdb`.`CurrentBalance`
ELSE CASE WHEN (SELECT Activity) = "withdraw" OR (SELECT Activity) = "bet"
THEN CASE WHEN (SELECT Payout) >0 THEN (SELECT Payout) + `playerdb`.`CurrentBalance`
ELSE `Amount` - `playerdb`.`CurrentBalance` END END END AS CurrentBalance
FROM `transactiondb` LEFT JOIN `playerdb` ON
`transactiondb`.`PlayerID` = `playerdb`.`PlayerID`
WHERE `transactiondb`.`PlayerID`=10078 UNION ALL
SELECT CONCAT("Bet ID ",`BetID`),`DateTime`,"Bet", `BetAmount`,`Payout`, (SELECT CurrentBalance) FROM `betdb` WHERE `PlayerID`=10078 ORDER BY `DateTime`
The Idea http://postimg.org/image/x3fsxq2qz/
Doing the (SELECT CurrentBalance) on the 2nd SELECT statement yields this error
1054 - Unknown column 'CurrentBalance' in 'field list'
I need to get the CurrentBalance of the previous record so I tried using the alias
Is that possible?