mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
99 lines
13 KiB
JSON
99 lines
13 KiB
JSON
{
|
||
"data": {
|
||
"question": {
|
||
"questionId": "1734",
|
||
"questionFrontendId": "1587",
|
||
"categoryTitle": "Database",
|
||
"boundTopicId": 418636,
|
||
"title": "Bank Account Summary II",
|
||
"titleSlug": "bank-account-summary-ii",
|
||
"content": "<p>Table: <code>Users</code></p>\n\n<pre>\n+--------------+---------+\n| Column Name | Type |\n+--------------+---------+\n| account | int |\n| name | varchar |\n+--------------+---------+\naccount is the primary key (column with unique values) for this table.\nEach row of this table contains the account number of each user in the bank.\nThere will be no two users having the same name in the table.\n</pre>\n\n<p> </p>\n\n<p>Table: <code>Transactions</code></p>\n\n<pre>\n+---------------+---------+\n| Column Name | Type |\n+---------------+---------+\n| trans_id | int |\n| account | int |\n| amount | int |\n| transacted_on | date |\n+---------------+---------+\ntrans_id is the primary key (column with unique values) for this table.\nEach row of this table contains all changes made to all accounts.\namount is positive if the user received money and negative if they transferred money.\nAll accounts start with a balance of 0.\n</pre>\n\n<p> </p>\n\n<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>\n\n<p>Return the result table in <strong>any order</strong>.</p>\n\n<p>The result format is in the following example.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \nUsers table:\n+------------+--------------+\n| account | name |\n+------------+--------------+\n| 900001 | Alice |\n| 900002 | Bob |\n| 900003 | Charlie |\n+------------+--------------+\nTransactions table:\n+------------+------------+------------+---------------+\n| trans_id | account | amount | transacted_on |\n+------------+------------+------------+---------------+\n| 1 | 900001 | 7000 | 2020-08-01 |\n| 2 | 900001 | 7000 | 2020-09-01 |\n| 3 | 900001 | -3000 | 2020-09-02 |\n| 4 | 900002 | 1000 | 2020-09-12 |\n| 5 | 900003 | 6000 | 2020-08-07 |\n| 6 | 900003 | 6000 | 2020-09-07 |\n| 7 | 900003 | -4000 | 2020-09-11 |\n+------------+------------+------------+---------------+\n<strong>Output:</strong> \n+------------+------------+\n| name | balance |\n+------------+------------+\n| Alice | 11000 |\n+------------+------------+\n<strong>Explanation:</strong> \nAlice's balance is (7000 + 7000 - 3000) = 11000.\nBob's balance is 1000.\nCharlie's balance is (6000 + 6000 - 4000) = 8000.\n</pre>\n",
|
||
"translatedTitle": "银行账户概要 II",
|
||
"translatedContent": "<p>表: <code>Users</code></p>\n\n<pre>\n+--------------+---------+\n| Column Name | Type |\n+--------------+---------+\n| account | int |\n| name | varchar |\n+--------------+---------+\naccount 是该表的主键(具有唯一值的列)。\n该表的每一行都包含银行中每个用户的帐号。\n表中不会有两个用户具有相同的名称。\n</pre>\n\n<p> </p>\n\n<p>表: <code>Transactions</code></p>\n\n<pre>\n+---------------+---------+\n| Column Name | Type |\n+---------------+---------+\n| trans_id | int |\n| account | int |\n| amount | int |\n| transacted_on | date |\n+---------------+---------+\ntrans_id 是该表主键(具有唯一值的列)。\n该表的每一行包含了所有账户的交易改变情况。\n如果用户收到了钱, 那么金额是正的; 如果用户转了钱, 那么金额是负的。\n所有账户的起始余额为 0。\n</pre>\n\n<p> </p>\n\n<p>编写解决方案, 报告余额高于 10000 的所有用户的名字和余额. 账户的余额等于包含该账户的所有交易的总和。</p>\n\n<p>返回结果表单 <strong>无顺序要求</strong> 。</p>\n\n<p>查询结果格式如下例所示。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre>\n<code><strong>输入:</strong>\nUsers</code> table:\n+------------+--------------+\n| account | name |\n+------------+--------------+\n| 900001 | Alice |\n| 900002 | Bob |\n| 900003 | Charlie |\n+------------+--------------+\n\n<code>Transactions</code> table:\n+------------+------------+------------+---------------+\n| trans_id | account | amount | transacted_on |\n+------------+------------+------------+---------------+\n| 1 | 900001 | 7000 | 2020-08-01 |\n| 2 | 900001 | 7000 | 2020-09-01 |\n| 3 | 900001 | -3000 | 2020-09-02 |\n| 4 | 900002 | 1000 | 2020-09-12 |\n| 5 | 900003 | 6000 | 2020-08-07 |\n| 6 | 900003 | 6000 | 2020-09-07 |\n| 7 | 900003 | -4000 | 2020-09-11 |\n+------------+------------+------------+---------------+\n<strong>输出:</strong>\n+------------+------------+\n| <code>name </code> | <code>balance </code> |\n+------------+------------+\n| Alice | 11000 |\n+------------+------------+\n<strong>解释:</strong>\nAlice 的余额为(7000 + 7000 - 3000) = 11000.\nBob 的余额为1000.\nCharlie 的余额为(6000 + 6000 - 4000) = 8000.\n</pre>\n",
|
||
"isPaidOnly": false,
|
||
"difficulty": "Easy",
|
||
"likes": 42,
|
||
"dislikes": 0,
|
||
"isLiked": null,
|
||
"similarQuestions": "[]",
|
||
"contributors": [],
|
||
"langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}",
|
||
"topicTags": [
|
||
{
|
||
"name": "Database",
|
||
"slug": "database",
|
||
"translatedName": "数据库",
|
||
"__typename": "TopicTagNode"
|
||
}
|
||
],
|
||
"companyTagStats": null,
|
||
"codeSnippets": [
|
||
{
|
||
"lang": "MySQL",
|
||
"langSlug": "mysql",
|
||
"code": "# Write your MySQL query statement below",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "MS SQL Server",
|
||
"langSlug": "mssql",
|
||
"code": "/* Write your T-SQL query statement below */",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "Oracle",
|
||
"langSlug": "oraclesql",
|
||
"code": "/* Write your PL/SQL query statement below */",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "Pandas",
|
||
"langSlug": "pythondata",
|
||
"code": "import pandas as pd\n\ndef account_summary(users: pd.DataFrame, transactions: pd.DataFrame) -> pd.DataFrame:\n ",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "PostgreSQL",
|
||
"langSlug": "postgresql",
|
||
"code": "-- Write your PostgreSQL query statement below",
|
||
"__typename": "CodeSnippetNode"
|
||
}
|
||
],
|
||
"stats": "{\"totalAccepted\": \"33.5K\", \"totalSubmission\": \"42.2K\", \"totalAcceptedRaw\": 33531, \"totalSubmissionRaw\": 42220, \"acRate\": \"79.4%\"}",
|
||
"hints": [],
|
||
"solution": null,
|
||
"status": null,
|
||
"sampleTestCase": "{\"headers\": {\"Users\": [\"account\", \"name\"], \"Transactions\": [\"trans_id\", \"account\", \"amount\", \"transacted_on\"]}, \"rows\": {\"Users\": [[900001, \"Alice\"], [900002, \"Bob\"], [900003, \"Charlie\"]], \"Transactions\": [[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\"]]}}",
|
||
"metaData": "{\"mysql\":[\"Create table If Not Exists Users (account int, name varchar(20))\",\"Create table If Not Exists Transactions (trans_id int, account int, amount int, transacted_on date)\"],\"mssql\":[\"Create table Users (account int, name varchar(20))\",\"Create table Transactions (trans_id int, account int, amount int, transacted_on date)\"],\"oraclesql\":[\"Create table Users (account int, name varchar(20))\",\"Create table Transactions (trans_id int, account int, amount int, transacted_on date)\",\"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"],\"database\":true,\"name\":\"account_summary\",\"pythondata\":[\"Users = pd.DataFrame([], columns=['account', 'name']).astype({'account':'Int64', 'name':'object'})\",\"Transactions = pd.DataFrame([], columns=['trans_id', 'account', 'amount', 'transacted_on']).astype({'trans_id':'Int64', 'account':'Int64', 'amount':'Int64', 'transacted_on':'datetime64[ns]'})\"],\"postgresql\":[\"\\nCreate table If Not Exists Users (account int, name varchar(20))\\n\",\"Create table If Not Exists Transactions (trans_id int, account int, amount int, transacted_on date)\"],\"database_schema\":{\"Users\":{\"account\":\"INT\",\"name\":\"VARCHAR(20)\"},\"Transactions\":{\"trans_id\":\"INT\",\"account\":\"INT\",\"amount\":\"INT\",\"transacted_on\":\"DATE\"}}}",
|
||
"judgerAvailable": true,
|
||
"judgeType": "large",
|
||
"mysqlSchemas": [
|
||
"Create table If Not Exists Users (account int, name varchar(20))",
|
||
"Create table If Not Exists Transactions (trans_id int, account int, amount int, transacted_on date)",
|
||
"Truncate table Users",
|
||
"insert into Users (account, name) values ('900001', 'Alice')",
|
||
"insert into Users (account, name) values ('900002', 'Bob')",
|
||
"insert into Users (account, name) values ('900003', 'Charlie')",
|
||
"Truncate table Transactions",
|
||
"insert into Transactions (trans_id, account, amount, transacted_on) values ('1', '900001', '7000', '2020-08-01')",
|
||
"insert into Transactions (trans_id, account, amount, transacted_on) values ('2', '900001', '7000', '2020-09-01')",
|
||
"insert into Transactions (trans_id, account, amount, transacted_on) values ('3', '900001', '-3000', '2020-09-02')",
|
||
"insert into Transactions (trans_id, account, amount, transacted_on) values ('4', '900002', '1000', '2020-09-12')",
|
||
"insert into Transactions (trans_id, account, amount, transacted_on) values ('5', '900003', '6000', '2020-08-07')",
|
||
"insert into Transactions (trans_id, account, amount, transacted_on) values ('6', '900003', '6000', '2020-09-07')",
|
||
"insert into Transactions (trans_id, account, amount, transacted_on) values ('7', '900003', '-4000', '2020-09-11')"
|
||
],
|
||
"enableRunCode": true,
|
||
"envInfo": "{\"mysql\":[\"MySQL\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>PostgreSQL 16<\\/p>\"]}",
|
||
"book": null,
|
||
"isSubscribed": false,
|
||
"isDailyQuestion": false,
|
||
"dailyRecordStatus": null,
|
||
"editorType": "CKEDITOR",
|
||
"ugcQuestionId": null,
|
||
"style": "LEETCODE",
|
||
"exampleTestcases": "{\"headers\": {\"Users\": [\"account\", \"name\"], \"Transactions\": [\"trans_id\", \"account\", \"amount\", \"transacted_on\"]}, \"rows\": {\"Users\": [[900001, \"Alice\"], [900002, \"Bob\"], [900003, \"Charlie\"]], \"Transactions\": [[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\"]]}}",
|
||
"__typename": "QuestionNode"
|
||
}
|
||
}
|
||
} |