1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/originData/restaurant-growth.json
2023-12-09 19:57:46 +08:00

98 lines
13 KiB
JSON

{
"data": {
"question": {
"questionId": "1452",
"questionFrontendId": "1321",
"categoryTitle": "Database",
"boundTopicId": 74822,
"title": "Restaurant Growth",
"titleSlug": "restaurant-growth",
"content": "<p>Table: <code>Customer</code></p>\n\n<pre>\n+---------------+---------+\n| Column Name | Type |\n+---------------+---------+\n| customer_id | int |\n| name | varchar |\n| visited_on | date |\n| amount | int |\n+---------------+---------+\nIn SQL,(customer_id, visited_on) is the primary key for this table.\nThis table contains data about customer transactions in a restaurant.\nvisited_on is the date on which the customer with ID (customer_id) has visited the restaurant.\namount is the total paid by a customer.\n</pre>\n\n<p>&nbsp;</p>\n\n<p>You are the restaurant owner and you want to analyze a possible expansion (there will be at least one customer every day).</p>\n\n<p>Compute the moving average of how much the customer paid in a seven days window (i.e., current day + 6 days before). <code>average_amount</code> should be <strong>rounded to two decimal places</strong>.</p>\n\n<p>Return the result table ordered by <code>visited_on</code> <strong>in ascending order</strong>.</p>\n\n<p>The result format is in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \nCustomer table:\n+-------------+--------------+--------------+-------------+\n| customer_id | name | visited_on | amount |\n+-------------+--------------+--------------+-------------+\n| 1 | Jhon | 2019-01-01 | 100 |\n| 2 | Daniel | 2019-01-02 | 110 |\n| 3 | Jade | 2019-01-03 | 120 |\n| 4 | Khaled | 2019-01-04 | 130 |\n| 5 | Winston | 2019-01-05 | 110 | \n| 6 | Elvis | 2019-01-06 | 140 | \n| 7 | Anna | 2019-01-07 | 150 |\n| 8 | Maria | 2019-01-08 | 80 |\n| 9 | Jaze | 2019-01-09 | 110 | \n| 1 | Jhon | 2019-01-10 | 130 | \n| 3 | Jade | 2019-01-10 | 150 | \n+-------------+--------------+--------------+-------------+\n<strong>Output:</strong> \n+--------------+--------------+----------------+\n| visited_on | amount | average_amount |\n+--------------+--------------+----------------+\n| 2019-01-07 | 860 | 122.86 |\n| 2019-01-08 | 840 | 120 |\n| 2019-01-09 | 840 | 120 |\n| 2019-01-10 | 1000 | 142.86 |\n+--------------+--------------+----------------+\n<strong>Explanation:</strong> \n1st moving average from 2019-01-01 to 2019-01-07 has an average_amount of (100 + 110 + 120 + 130 + 110 + 140 + 150)/7 = 122.86\n2nd moving average from 2019-01-02 to 2019-01-08 has an average_amount of (110 + 120 + 130 + 110 + 140 + 150 + 80)/7 = 120\n3rd moving average from 2019-01-03 to 2019-01-09 has an average_amount of (120 + 130 + 110 + 140 + 150 + 80 + 110)/7 = 120\n4th moving average from 2019-01-04 to 2019-01-10 has an average_amount of (130 + 110 + 140 + 150 + 80 + 110 + 130 + 150)/7 = 142.86\n</pre>\n",
"translatedTitle": "餐馆营业额变化增长",
"translatedContent": "<p>表: <code>Customer</code></p>\n\n<pre>\n+---------------+---------+\n| Column Name | Type |\n+---------------+---------+\n| customer_id | int |\n| name | varchar |\n| visited_on | date |\n| amount | int |\n+---------------+---------+\n在 SQL 中,(customer_id, visited_on) 是该表的主键。\n该表包含一家餐馆的顾客交易数据。\nvisited_on 表示 (customer_id) 的顾客在 visited_on 那天访问了餐馆。\namount 是一个顾客某一天的消费总额。\n</pre>\n\n<p>&nbsp;</p>\n\n<p>你是餐馆的老板,现在你想分析一下可能的营业额变化增长(每天至少有一位顾客)。</p>\n\n<p>计算以 7 天(某日期 + 该日期前的 6 天)为一个时间段的顾客消费平均值。<code>average_amount</code>&nbsp;要 <strong>保留两位小数。</strong></p>\n\n<p>结果按 <code>visited_on</code>&nbsp;<strong>升序排序</strong>。</p>\n\n<p>返回结果格式的例子如下。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre>\n<strong>输入:</strong>\nCustomer 表:\n+-------------+--------------+--------------+-------------+\n| customer_id | name | visited_on | amount |\n+-------------+--------------+--------------+-------------+\n| 1 | Jhon | 2019-01-01 | 100 |\n| 2 | Daniel | 2019-01-02 | 110 |\n| 3 | Jade | 2019-01-03 | 120 |\n| 4 | Khaled | 2019-01-04 | 130 |\n| 5 | Winston | 2019-01-05 | 110 | \n| 6 | Elvis | 2019-01-06 | 140 | \n| 7 | Anna | 2019-01-07 | 150 |\n| 8 | Maria | 2019-01-08 | 80 |\n| 9 | Jaze | 2019-01-09 | 110 | \n| 1 | Jhon | 2019-01-10 | 130 | \n| 3 | Jade | 2019-01-10 | 150 | \n+-------------+--------------+--------------+-------------+\n<strong>输出:</strong>\n+--------------+--------------+----------------+\n| visited_on | amount | average_amount |\n+--------------+--------------+----------------+\n| 2019-01-07 | 860 | 122.86 |\n| 2019-01-08 | 840 | 120 |\n| 2019-01-09 | 840 | 120 |\n| 2019-01-10 | 1000 | 142.86 |\n+--------------+--------------+----------------+\n<strong>解释:</strong>\n第一个七天消费平均值从 2019-01-01 到 2019-01-07 是restaurant-growth/restaurant-growth/ (100 + 110 + 120 + 130 + 110 + 140 + 150)/7 = 122.86\n第二个七天消费平均值从 2019-01-02 到 2019-01-08 是 (110 + 120 + 130 + 110 + 140 + 150 + 80)/7 = 120\n第三个七天消费平均值从 2019-01-03 到 2019-01-09 是 (120 + 130 + 110 + 140 + 150 + 80 + 110)/7 = 120\n第四个七天消费平均值从 2019-01-04 到 2019-01-10 是 (130 + 110 + 140 + 150 + 80 + 110 + 130 + 150)/7 = 142.86</pre>\n",
"isPaidOnly": false,
"difficulty": "Medium",
"likes": 151,
"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 restaurant_growth(customer: pd.DataFrame) -> pd.DataFrame:\n ",
"__typename": "CodeSnippetNode"
},
{
"lang": "PostgreSQL",
"langSlug": "postgresql",
"code": "-- Write your PostgreSQL query statement below",
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"18.7K\", \"totalSubmission\": \"35.9K\", \"totalAcceptedRaw\": 18742, \"totalSubmissionRaw\": 35855, \"acRate\": \"52.3%\"}",
"hints": [],
"solution": null,
"status": null,
"sampleTestCase": "{\"headers\":{\"Customer\":[\"customer_id\",\"name\",\"visited_on\",\"amount\"]},\"rows\":{\"Customer\":[[1,\"Jhon\",\"2019-01-01\",100],[2,\"Daniel\",\"2019-01-02\",110],[3,\"Jade\",\"2019-01-03\",120],[4,\"Khaled\",\"2019-01-04\",130],[5,\"Winston\",\"2019-01-05\",110],[6,\"Elvis\",\"2019-01-06\",140],[7,\"Anna\",\"2019-01-07\",150],[8,\"Maria\",\"2019-01-08\",80],[9,\"Jaze\",\"2019-01-09\",110],[1,\"Jhon\",\"2019-01-10\",130],[3,\"Jade\",\"2019-01-10\",150]]}}",
"metaData": "{\"mysql\":[\"Create table If Not Exists Customer (customer_id int, name varchar(20), visited_on date, amount int)\"],\"mssql\":[\"Create table Customer (customer_id int, name varchar(20), visited_on date, amount int)\"],\"oraclesql\":[\"Create table Customer (customer_id int, name varchar(20), visited_on date, amount int)\",\"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"],\"database\":true,\"name\":\"restaurant_growth\",\"pythondata\":[\"Customer = pd.DataFrame([], columns=['customer_id', 'name', 'visited_on', 'amount']).astype({'customer_id':'Int64', 'name':'object', 'visited_on':'datetime64[ns]', 'amount':'Int64'})\"],\"postgresql\":[\"\\nCreate table If Not Exists Customer (customer_id int, name varchar(20), visited_on date, amount int)\"],\"database_schema\":{\"Customer\":{\"customer_id\":\"INT\",\"name\":\"VARCHAR(20)\",\"visited_on\":\"DATE\",\"amount\":\"INT\"}}}",
"judgerAvailable": true,
"judgeType": "large",
"mysqlSchemas": [
"Create table If Not Exists Customer (customer_id int, name varchar(20), visited_on date, amount int)",
"Truncate table Customer",
"insert into Customer (customer_id, name, visited_on, amount) values ('1', 'Jhon', '2019-01-01', '100')",
"insert into Customer (customer_id, name, visited_on, amount) values ('2', 'Daniel', '2019-01-02', '110')",
"insert into Customer (customer_id, name, visited_on, amount) values ('3', 'Jade', '2019-01-03', '120')",
"insert into Customer (customer_id, name, visited_on, amount) values ('4', 'Khaled', '2019-01-04', '130')",
"insert into Customer (customer_id, name, visited_on, amount) values ('5', 'Winston', '2019-01-05', '110')",
"insert into Customer (customer_id, name, visited_on, amount) values ('6', 'Elvis', '2019-01-06', '140')",
"insert into Customer (customer_id, name, visited_on, amount) values ('7', 'Anna', '2019-01-07', '150')",
"insert into Customer (customer_id, name, visited_on, amount) values ('8', 'Maria', '2019-01-08', '80')",
"insert into Customer (customer_id, name, visited_on, amount) values ('9', 'Jaze', '2019-01-09', '110')",
"insert into Customer (customer_id, name, visited_on, amount) values ('1', 'Jhon', '2019-01-10', '130')",
"insert into Customer (customer_id, name, visited_on, amount) values ('3', 'Jade', '2019-01-10', '150')"
],
"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\":{\"Customer\":[\"customer_id\",\"name\",\"visited_on\",\"amount\"]},\"rows\":{\"Customer\":[[1,\"Jhon\",\"2019-01-01\",100],[2,\"Daniel\",\"2019-01-02\",110],[3,\"Jade\",\"2019-01-03\",120],[4,\"Khaled\",\"2019-01-04\",130],[5,\"Winston\",\"2019-01-05\",110],[6,\"Elvis\",\"2019-01-06\",140],[7,\"Anna\",\"2019-01-07\",150],[8,\"Maria\",\"2019-01-08\",80],[9,\"Jaze\",\"2019-01-09\",110],[1,\"Jhon\",\"2019-01-10\",130],[3,\"Jade\",\"2019-01-10\",150]]}}",
"__typename": "QuestionNode"
}
}
}