1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 11:08:15 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/银行账户概要 II [bank-account-summary-ii].html

80 lines
2.5 KiB
HTML
Raw Normal View History

2022-03-27 20:45:09 +08:00
<p>表: <code>Users</code></p>
2023-12-09 18:42:21 +08:00
<pre>
+--------------+---------+
2022-03-27 20:45:09 +08:00
| Column Name | Type |
+--------------+---------+
| account | int |
| name | varchar |
+--------------+---------+
2023-12-09 18:42:21 +08:00
account 是该表的主键(具有唯一值的列)。
该表的每一行都包含银行中每个用户的帐号。
表中不会有两个用户具有相同的名称。
2022-03-27 20:45:09 +08:00
</pre>
<p>&nbsp;</p>
<p>表: <code>Transactions</code></p>
2023-12-09 18:42:21 +08:00
<pre>
+---------------+---------+
2022-03-27 20:45:09 +08:00
| Column Name | Type |
+---------------+---------+
| trans_id | int |
| account | int |
| amount | int |
| transacted_on | date |
+---------------+---------+
2023-12-09 18:42:21 +08:00
trans_id 是该表主键(具有唯一值的列)。
该表的每一行包含了所有账户的交易改变情况。
如果用户收到了钱, 那么金额是正的; 如果用户转了钱, 那么金额是负的。
所有账户的起始余额为 0。
2022-03-27 20:45:09 +08:00
</pre>
<p>&nbsp;</p>
2023-12-09 18:42:21 +08:00
<p>编写解决方案,&nbsp;&nbsp;报告余额高于 10000 的所有用户的名字和余额.&nbsp;账户的余额等于包含该账户的所有交易的总和。</p>
2022-03-27 20:45:09 +08:00
2023-12-09 18:42:21 +08:00
<p>返回结果表单 <strong>无顺序要求</strong></p>
2022-03-27 20:45:09 +08:00
2023-12-09 18:42:21 +08:00
<p>查询结果格式如下例所示。</p>
2022-03-27 20:45:09 +08:00
<p>&nbsp;</p>
2023-12-09 18:42:21 +08:00
<p><strong>示例 1</strong></p>
<pre>
<code><strong>输入:</strong>
Users</code> table:
2022-03-27 20:45:09 +08:00
+------------+--------------+
| account | name |
+------------+--------------+
| 900001 | Alice |
| 900002 | Bob |
| 900003 | Charlie |
+------------+--------------+
<code>Transactions</code> 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 |
+------------+------------+------------+---------------+
2023-12-09 18:42:21 +08:00
<strong>输出:</strong>
2022-03-27 20:45:09 +08:00
+------------+------------+
| <code>name </code> | <code>balance </code> |
+------------+------------+
| Alice | 11000 |
+------------+------------+
2023-12-09 18:42:21 +08:00
<strong>解释:</strong>
2022-03-27 20:45:09 +08:00
Alice 的余额为(7000 + 7000 - 3000) = 11000.
Bob 的余额为1000.
Charlie 的余额为(6000 + 6000 - 4000) = 8000.
</pre>