Skip to content

Commit 5b748cf

Browse files
committed
task: #1587
1 parent 15541c7 commit 5b748cf

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Have a good contributing!
5050
- [1068. Product Sales Analysis I](./leetcode/easy/1068.%20Product%20Sales%20Analysis%20I.sql)
5151
- [1407. Top Travellers](./leetcode/easy/1407.%20Top%20Travellers.sql)
5252
- [1484. Group Sold Products By The Date](./leetcode/easy/1484.%20Group%20Sold%20Products%20By%20The%20Date.sql)
53+
- [1587. Bank Account Summary II](./leetcode/easy/1587.%20Bank%20Account%20Summary%20II.sql)
5354
- [1693. Daily Leads and Partners](./leetcode/easy/1693.%20Daily%20Leads%20and%20Partners.sql)
5455
- [1729. Find Followers Count](./leetcode/easy/1729.%20Find%20Followers%20Count.sql)
5556
- [1741. Find Total Time Spent by Each Employee](./leetcode/easy/1741.%20Find%20Total%20Time%20Spent%20by%20Each%20Employee.sql)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
Question 1587. Bank Account Summary II
3+
Link: https://leetcode.com/problems/bank-account-summary-ii/description/
4+
5+
Table: Users
6+
7+
+--------------+---------+
8+
| Column Name | Type |
9+
+--------------+---------+
10+
| account | int |
11+
| name | varchar |
12+
+--------------+---------+
13+
account is the primary key (column with unique values) for this table.
14+
Each row of this table contains the account number of each user in the bank.
15+
There will be no two users having the same name in the table.
16+
17+
18+
Table: Transactions
19+
20+
+---------------+---------+
21+
| Column Name | Type |
22+
+---------------+---------+
23+
| trans_id | int |
24+
| account | int |
25+
| amount | int |
26+
| transacted_on | date |
27+
+---------------+---------+
28+
trans_id is the primary key (column with unique values) for this table.
29+
Each row of this table contains all changes made to all accounts.
30+
amount is positive if the user received money and negative if they transferred money.
31+
All accounts start with a balance of 0.
32+
33+
34+
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.
35+
36+
Return the result table in any order.
37+
*/
38+
39+
SELECT
40+
u.name,
41+
SUM(t.amount) AS balance
42+
FROM Transactions AS t
43+
LEFT JOIN
44+
Users AS u
45+
ON t.account = u.account
46+
GROUP BY u.name
47+
HAVING SUM(t.amount) > 10000

0 commit comments

Comments
 (0)