mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
91 lines
10 KiB
JSON
91 lines
10 KiB
JSON
{
|
|
"data": {
|
|
"question": {
|
|
"questionId": "1317",
|
|
"questionFrontendId": "1193",
|
|
"categoryTitle": "Database",
|
|
"boundTopicId": 27992,
|
|
"title": "Monthly Transactions I",
|
|
"titleSlug": "monthly-transactions-i",
|
|
"content": "<p>Table: <code>Transactions</code></p>\n\n<pre>\n+---------------+---------+\n| Column Name | Type |\n+---------------+---------+\n| id | int |\n| country | varchar |\n| state | enum |\n| amount | int |\n| trans_date | date |\n+---------------+---------+\nid is the primary key of this table.\nThe table has information about incoming transactions.\nThe state column is an enum of type ["approved", "declined"].\n</pre>\n\n<p> </p>\n\n<p>Write an SQL query to find for each month and country, the number of transactions and their total amount, the number of approved transactions and their total amount.</p>\n\n<p>Return the result table in <strong>any order</strong>.</p>\n\n<p>The query 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> \nTransactions table:\n+------+---------+----------+--------+------------+\n| id | country | state | amount | trans_date |\n+------+---------+----------+--------+------------+\n| 121 | US | approved | 1000 | 2018-12-18 |\n| 122 | US | declined | 2000 | 2018-12-19 |\n| 123 | US | approved | 2000 | 2019-01-01 |\n| 124 | DE | approved | 2000 | 2019-01-07 |\n+------+---------+----------+--------+------------+\n<strong>Output:</strong> \n+----------+---------+-------------+----------------+--------------------+-----------------------+\n| month | country | trans_count | approved_count | trans_total_amount | approved_total_amount |\n+----------+---------+-------------+----------------+--------------------+-----------------------+\n| 2018-12 | US | 2 | 1 | 3000 | 1000 |\n| 2019-01 | US | 1 | 1 | 2000 | 2000 |\n| 2019-01 | DE | 1 | 1 | 2000 | 2000 |\n+----------+---------+-------------+----------------+--------------------+-----------------------+\n</pre>\n",
|
|
"translatedTitle": "每月交易 I",
|
|
"translatedContent": "<p>表:<code>Transactions</code></p>\n\n<pre>\n+---------------+---------+\n| Column Name | Type |\n+---------------+---------+\n| id | int |\n| country | varchar |\n| state | enum |\n| amount | int |\n| trans_date | date |\n+---------------+---------+\nid 是这个表的主键。\n该表包含有关传入事务的信息。\nstate 列类型为 [\"approved\", \"declined\"] 之一。\n</pre>\n\n<p> </p>\n\n<p>编写一个 sql 查询来查找每个月和每个国家/地区的事务数及其总金额、已批准的事务数及其总金额。</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>\nTransactions</code> table:\n+------+---------+----------+--------+------------+\n| id | country | state | amount | trans_date |\n+------+---------+----------+--------+------------+\n| 121 | US | approved | 1000 | 2018-12-18 |\n| 122 | US | declined | 2000 | 2018-12-19 |\n| 123 | US | approved | 2000 | 2019-01-01 |\n| 124 | DE | approved | 2000 | 2019-01-07 |\n+------+---------+----------+--------+------------+\n<strong>输出:</strong>\n+----------+---------+-------------+----------------+--------------------+-----------------------+\n| month | country | trans_count | approved_count | trans_total_amount | approved_total_amount |\n+----------+---------+-------------+----------------+--------------------+-----------------------+\n| 2018-12 | US | 2 | 1 | 3000 | 1000 |\n| 2019-01 | US | 1 | 1 | 2000 | 2000 |\n| 2019-01 | DE | 1 | 1 | 2000 | 2000 |\n+----------+---------+-------------+----------------+--------------------+-----------------------+</pre>\n",
|
|
"isPaidOnly": false,
|
|
"difficulty": "Medium",
|
|
"likes": 93,
|
|
"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 monthly_transactions(transactions: pd.DataFrame) -> pd.DataFrame:\n ",
|
|
"__typename": "CodeSnippetNode"
|
|
},
|
|
{
|
|
"lang": "PostgreSQL",
|
|
"langSlug": "postgresql",
|
|
"code": "-- Write your PostgreSQL query statement below",
|
|
"__typename": "CodeSnippetNode"
|
|
}
|
|
],
|
|
"stats": "{\"totalAccepted\": \"29K\", \"totalSubmission\": \"47.5K\", \"totalAcceptedRaw\": 28978, \"totalSubmissionRaw\": 47534, \"acRate\": \"61.0%\"}",
|
|
"hints": [],
|
|
"solution": null,
|
|
"status": null,
|
|
"sampleTestCase": "{\"headers\":{\"Transactions\":[\"id\",\"country\",\"state\",\"amount\",\"trans_date\"]},\"rows\":{\"Transactions\":[[121,\"US\",\"approved\",1000,\"2018-12-18\"],[122,\"US\",\"declined\",2000,\"2018-12-19\"],[123,\"US\",\"approved\",2000,\"2019-01-01\"],[124,\"DE\",\"approved\",2000,\"2019-01-07\"]]}}",
|
|
"metaData": "{\"mysql\":[\"Create table If Not Exists Transactions (id int, country varchar(4), state enum('approved', 'declined'), amount int, trans_date date)\"],\"mssql\":[\"Create table Transactions (id int, country varchar(4), state varchar(10) check(state in ('approved', 'declined')), amount int, trans_date date)\"],\"oraclesql\":[\"Create table Transactions (id int, country varchar(4), state varchar(10) check(state in ('approved', 'declined')), amount int, trans_date date)\",\"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"],\"database\":true,\"name\":\"monthly_transactions\",\"pythondata\":[\"Transactions = pd.DataFrame([], columns=['id', 'country', 'state', 'amount', 'trans_date']).astype({'id':'Int64', 'country':'object', 'state':'object', 'amount':'Int64', 'trans_date':'datetime64[ns]'})\"],\"postgresql\":[\"Create table If Not Exists Transactions (id int, country varchar(4), state VARCHAR(30) CHECK (state IN ('approved', 'declined')), amount int, trans_date date)\\n\\n\"],\"database_schema\":{\"Transactions\":{\"id\":\"INT\",\"country\":\"VARCHAR(4)\",\"state\":\"ENUM('approved', 'declined')\",\"amount\":\"INT\",\"trans_date\":\"DATE\"}}}",
|
|
"judgerAvailable": true,
|
|
"judgeType": "large",
|
|
"mysqlSchemas": [
|
|
"Create table If Not Exists Transactions (id int, country varchar(4), state enum('approved', 'declined'), amount int, trans_date date)",
|
|
"Truncate table Transactions",
|
|
"insert into Transactions (id, country, state, amount, trans_date) values ('121', 'US', 'approved', '1000', '2018-12-18')",
|
|
"insert into Transactions (id, country, state, amount, trans_date) values ('122', 'US', 'declined', '2000', '2018-12-19')",
|
|
"insert into Transactions (id, country, state, amount, trans_date) values ('123', 'US', 'approved', '2000', '2019-01-01')",
|
|
"insert into Transactions (id, country, state, amount, trans_date) values ('124', 'DE', 'approved', '2000', '2019-01-07')"
|
|
],
|
|
"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\":{\"Transactions\":[\"id\",\"country\",\"state\",\"amount\",\"trans_date\"]},\"rows\":{\"Transactions\":[[121,\"US\",\"approved\",1000,\"2018-12-18\"],[122,\"US\",\"declined\",2000,\"2018-12-19\"],[123,\"US\",\"approved\",2000,\"2019-01-01\"],[124,\"DE\",\"approved\",2000,\"2019-01-07\"]]}}",
|
|
"__typename": "QuestionNode"
|
|
}
|
|
}
|
|
} |