+--------------+---------+
|Column Name |Type|+--------------+---------+
| account | int || name | varchar |+--------------+---------+
account is the primarykey (columnwithuniquevalues) for this table.
Eachrowof this tablecontains the account number ofeachuserin the bank.
There will be no two users having the same name in the table.
Table: Transactions
1
2
3
4
5
6
7
8
+---------------+---------+
|Column Name |Type|+---------------+---------+
| trans_id | int || account | int || amount | int || transacted_on | date |+---------------+---------+
trans_id is the primary key (column with unique values) for this table.
Each row of this table contains all changes made to all accounts.
amount is positive if the user received money and negative if they transferred money.
All accounts start with a balance of 0.
Write a solution to report the name and balance of users with a balance higher than 10000. The balance of an account is equal to the sum of the amounts of all transactions involving that account.
SELECT u.name, t.balance
FROM Users u
JOIN (
SELECT account, SUM(amount) AS balance
FROM Transactions
GROUPBY account
) t ON u.account = t.account
WHERE t.balance >10000;