-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path1587. Bank Account Summary II.sql
More file actions
47 lines (38 loc) · 1.39 KB
/
1587. Bank Account Summary II.sql
File metadata and controls
47 lines (38 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
Question 1587. Bank Account Summary II
Link: https://leetcode.com/problems/bank-account-summary-ii/description/
Table: Users
+--------------+---------+
| Column Name | Type |
+--------------+---------+
| account | int |
| name | varchar |
+--------------+---------+
account is the primary key (column with unique values) for this table.
Each row of this table contains the account number of each user in the bank.
There will be no two users having the same name in the table.
Table: Transactions
+---------------+---------+
| 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.
Return the result table in any order.
*/
SELECT
u.name,
SUM(t.amount) AS balance
FROM Transactions AS t
LEFT JOIN
Users AS u
ON t.account = u.account
GROUP BY u.name
HAVING SUM(t.amount) > 10000