I have two different Select statements which are producing correct results, but I'm curious if this can be done in one Select?
SELECT UserInfo.Id, AVG(BalanceInfo.Bet) as 'Avg bet'
FROM [USERINFO] as UserInfo
JOIN [BALANCEINFO] as BalanceInfo
ON UserInfo.Id = BalanceInfo.UserId
WHERE UserInfo.RoomId = 84 AND BalanceInfo.Bet != 0
GROUP BY UserInfo.Id
SELECT UserInfo.Id, SUM(BalanceInfo.Profit) as 'Deposits'
FROM [USERINFO] as UserInfo
JOIN [BALANCEINFO] as BalanceInfo
ON UserInfo.Id = BalanceInfo.UserId
WHERE UserInfo.RoomId = 84 AND BalanceInfo.ChangeType = 8 AND BalanceInfo.Profit > 0
GROUP BY UserInfo.Id
As you may see the difference is in Where statements.
The first Select produces average bets for every user and the second Select produces sum of the deposits for every user, which are two different tables. Can it be done in one instead?