1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-26 02:00:27 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode/problem/bank-account-summary-ii.html

78 lines
2.6 KiB
HTML
Raw Normal View History

2022-03-27 18:27:43 +08:00
<p>Table: <code>Users</code></p>
<pre>
+--------------+---------+
| Column Name | Type |
+--------------+---------+
| account | int |
| name | varchar |
+--------------+---------+
2023-12-09 18:42:21 +08:00
account is the primary key (column with unique values) for this table.
2022-03-27 18:27:43 +08:00
Each row of this table contains the account number of each user in the bank.
2023-12-09 18:42:21 +08:00
There will be no two users having the same name in the table.
2022-03-27 18:27:43 +08:00
</pre>
<p>&nbsp;</p>
<p>Table: <code>Transactions</code></p>
<pre>
+---------------+---------+
| Column Name | Type |
+---------------+---------+
| trans_id | int |
| account | int |
| amount | int |
| transacted_on | date |
+---------------+---------+
2023-12-09 18:42:21 +08:00
trans_id is the primary key (column with unique values) for this table.
2022-03-27 18:27:43 +08:00
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.
</pre>
<p>&nbsp;</p>
2023-12-09 18:42:21 +08:00
<p>Write a solution to report the name and balance of users with a balance higher than <code>10000</code>. The balance of an account is equal to the sum of the amounts of all transactions involving that account.</p>
2022-03-27 18:27:43 +08:00
<p>Return the result table in <strong>any order</strong>.</p>
2023-12-09 18:42:21 +08:00
<p>The result format is in the following example.</p>
2022-03-27 18:27:43 +08:00
<p>&nbsp;</p>
2023-12-09 18:42:21 +08:00
<p><strong class="example">Example 1:</strong></p>
2022-03-27 18:27:43 +08:00
<pre>
<strong>Input:</strong>
Users table:
+------------+--------------+
| account | name |
+------------+--------------+
| 900001 | Alice |
| 900002 | Bob |
| 900003 | Charlie |
+------------+--------------+
Transactions table:
+------------+------------+------------+---------------+
| trans_id | account | amount | transacted_on |
+------------+------------+------------+---------------+
| 1 | 900001 | 7000 | 2020-08-01 |
| 2 | 900001 | 7000 | 2020-09-01 |
| 3 | 900001 | -3000 | 2020-09-02 |
| 4 | 900002 | 1000 | 2020-09-12 |
| 5 | 900003 | 6000 | 2020-08-07 |
| 6 | 900003 | 6000 | 2020-09-07 |
| 7 | 900003 | -4000 | 2020-09-11 |
+------------+------------+------------+---------------+
<strong>Output:</strong>
+------------+------------+
| name | balance |
+------------+------------+
| Alice | 11000 |
+------------+------------+
<strong>Explanation:</strong>
Alice&#39;s balance is (7000 + 7000 - 3000) = 11000.
Bob&#39;s balance is 1000.
Charlie&#39;s balance is (6000 + 6000 - 4000) = 8000.
</pre>