Answer the question
In order to leave comments, you need to log in
How to calculate user balance?
This is one of the tasks, the execution time is 11 minutes after opening the spoiler.
deposit + adjustment_up - adjustment_down - rollback (referenced deposit amount) - rollback (referenced adjus
name description
balance => result of provided formula
owner_id => ID of wallet owner
Answer the question
In order to leave comments, you need to log in
SELECT usesr.id, SUM(CASE WHEN transaction.type IN ('deposit', 'adjustment_up',)
THEN amount
WHEN transaction.type IN ('adjustment_down', 'rollback')
THEN -amount
ELSE 0
END) balance
FROM user
JOIN wallet ON iser.id = wallet.user_id
JOIN transaction ON wallet.id = transaction.wallet_id
GROUP BY user.id
I can assume that adjustment_up, adjustment_down and rollback are also types of transactions. You need to find all such transactions in the transaction table, related to a specific wallet_id and substitute it in the formula.
Next, you need to calculate the total balance for wallets owned by one user, and give it as a result.
PS Where is the task from?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question