mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-25 17:50:26 +08:00
95 lines
11 KiB
JSON
95 lines
11 KiB
JSON
{
|
||
"data": {
|
||
"question": {
|
||
"questionId": "1153",
|
||
"questionFrontendId": "1068",
|
||
"categoryTitle": "Database",
|
||
"boundTopicId": 7633,
|
||
"title": "Product Sales Analysis I",
|
||
"titleSlug": "product-sales-analysis-i",
|
||
"content": "<p>Table: <code>Sales</code></p>\n\n<pre>\n+-------------+-------+\n| Column Name | Type |\n+-------------+-------+\n| sale_id | int |\n| product_id | int |\n| year | int |\n| quantity | int |\n| price | int |\n+-------------+-------+\n(sale_id, year) is the primary key (combination of columns with unique values) of this table.\nproduct_id is a foreign key (reference column) to <code>Product</code> table.\nEach row of this table shows a sale on the product product_id in a certain year.\nNote that the price is per unit.\n</pre>\n\n<p> </p>\n\n<p>Table: <code>Product</code></p>\n\n<pre>\n+--------------+---------+\n| Column Name | Type |\n+--------------+---------+\n| product_id | int |\n| product_name | varchar |\n+--------------+---------+\nproduct_id is the primary key (column with unique values) of this table.\nEach row of this table indicates the product name of each product.\n</pre>\n\n<p> </p>\n\n<p>Write a solution to report the <code>product_name</code>, <code>year</code>, and <code>price</code> for each <code>sale_id</code> in the <code>Sales</code> table.</p>\n\n<p>Return the resulting 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> \nSales table:\n+---------+------------+------+----------+-------+\n| sale_id | product_id | year | quantity | price |\n+---------+------------+------+----------+-------+ \n| 1 | 100 | 2008 | 10 | 5000 |\n| 2 | 100 | 2009 | 12 | 5000 |\n| 7 | 200 | 2011 | 15 | 9000 |\n+---------+------------+------+----------+-------+\nProduct table:\n+------------+--------------+\n| product_id | product_name |\n+------------+--------------+\n| 100 | Nokia |\n| 200 | Apple |\n| 300 | Samsung |\n+------------+--------------+\n<strong>Output:</strong> \n+--------------+-------+-------+\n| product_name | year | price |\n+--------------+-------+-------+\n| Nokia | 2008 | 5000 |\n| Nokia | 2009 | 5000 |\n| Apple | 2011 | 9000 |\n+--------------+-------+-------+\n<strong>Explanation:</strong> \nFrom sale_id = 1, we can conclude that Nokia was sold for 5000 in the year 2008.\nFrom sale_id = 2, we can conclude that Nokia was sold for 5000 in the year 2009.\nFrom sale_id = 7, we can conclude that Apple was sold for 9000 in the year 2011.\n</pre>\n",
|
||
"translatedTitle": "产品销售分析 I",
|
||
"translatedContent": "<p>销售表 <code>Sales</code>:</p>\n\n<pre>\n+-------------+-------+\n| Column Name | Type |\n+-------------+-------+\n| sale_id | int |\n| product_id | int |\n| year | int |\n| quantity | int |\n| price | int |\n+-------------+-------+\n(sale_id, year) 是销售表 Sales 的主键(具有唯一值的列的组合)。\nproduct_id 是关联到产品表 Product 的外键(reference 列)。\n该表的每一行显示 product_id 在某一年的销售情况。\n注意: price 表示每单位价格。\n</pre>\n\n<p>产品表 <code>Product</code>:</p>\n\n<pre>\n+--------------+---------+\n| Column Name | Type |\n+--------------+---------+\n| product_id | int |\n| product_name | varchar |\n+--------------+---------+\nproduct_id 是表的主键(具有唯一值的列)。\n该表的每一行表示每种产品的产品名称。\n</pre>\n\n<p> </p>\n\n<p>编写解决方案,以获取 <code>Sales</code> 表中所有 <code>sale_id</code> 对应的 <code>product_name</code> 以及该产品的所有<strong> </strong><code>year</code> 和<strong> </strong><code>price</code> 。</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>\nSales</code> 表:\n+---------+------------+------+----------+-------+\n| sale_id | product_id | year | quantity | price |\n+---------+------------+------+----------+-------+ \n| 1 | 100 | 2008 | 10 | 5000 |\n| 2 | 100 | 2009 | 12 | 5000 |\n| 7 | 200 | 2011 | 15 | 9000 |\n+---------+------------+------+----------+-------+\nProduct 表:\n+------------+--------------+\n| product_id | product_name |\n+------------+--------------+\n| 100 | Nokia |\n| 200 | Apple |\n| 300 | Samsung |\n+------------+--------------+\n<strong>输出:</strong>\n+--------------+-------+-------+\n| product_name | year | price |\n+--------------+-------+-------+\n| Nokia | 2008 | 5000 |\n| Nokia | 2009 | 5000 |\n| Apple | 2011 | 9000 |\n+--------------+-------+-------+\n</pre>\n",
|
||
"isPaidOnly": false,
|
||
"difficulty": "Easy",
|
||
"likes": 56,
|
||
"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 sales_analysis(sales: pd.DataFrame, product: pd.DataFrame) -> pd.DataFrame:\n ",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "PostgreSQL",
|
||
"langSlug": "postgresql",
|
||
"code": "-- Write your PostgreSQL query statement below",
|
||
"__typename": "CodeSnippetNode"
|
||
}
|
||
],
|
||
"stats": "{\"totalAccepted\": \"54.2K\", \"totalSubmission\": \"61.9K\", \"totalAcceptedRaw\": 54164, \"totalSubmissionRaw\": 61904, \"acRate\": \"87.5%\"}",
|
||
"hints": [],
|
||
"solution": null,
|
||
"status": null,
|
||
"sampleTestCase": "{\"headers\":{\"Sales\":[\"sale_id\",\"product_id\",\"year\",\"quantity\",\"price\"],\"Product\":[\"product_id\",\"product_name\"]},\"rows\":{\"Sales\":[[1,100,2008,10,5000],[2,100,2009,12,5000],[7,200,2011,15,9000]],\"Product\":[[100,\"Nokia\"],[200,\"Apple\"],[300,\"Samsung\"]]}}",
|
||
"metaData": "{\"mysql\":[\"Create table If Not Exists Sales (sale_id int, product_id int, year int, quantity int, price int)\",\"Create table If Not Exists Product (product_id int, product_name varchar(10))\"],\"mssql\":[\"Create table Sales (sale_id int, product_id int, year int, quantity int, price int)\",\"Create table Product (product_id int, product_name varchar(10))\"],\"oraclesql\":[\"Create table Sales (sale_id int, product_id int, year int, quantity int, price int)\",\"Create table Product (product_id int, product_name varchar(10))\"],\"database\":true,\"name\":\"sales_analysis\",\"pythondata\":[\"Sales = pd.DataFrame([], columns=['sale_id', 'product_id', 'year', 'quantity', 'price']).astype({'sale_id':'Int64', 'product_id':'Int64', 'year':'Int64', 'quantity':'Int64', 'price':'Int64'})\",\"Product = pd.DataFrame([], columns=['product_id', 'product_name']).astype({'product_id':'Int64', 'product_name':'object'})\"],\"postgresql\":[\"Create table If Not Exists Sales (sale_id int, product_id int, year int, quantity int, price int)\\n\",\"Create table If Not Exists Product (product_id int, product_name varchar(10))\"],\"database_schema\":{\"Sales\":{\"sale_id\":\"INT\",\"product_id\":\"INT\",\"year\":\"INT\",\"quantity\":\"INT\",\"price\":\"INT\"},\"Product\":{\"product_id\":\"INT\",\"product_name\":\"VARCHAR(10)\"}}}",
|
||
"judgerAvailable": true,
|
||
"judgeType": "large",
|
||
"mysqlSchemas": [
|
||
"Create table If Not Exists Sales (sale_id int, product_id int, year int, quantity int, price int)",
|
||
"Create table If Not Exists Product (product_id int, product_name varchar(10))",
|
||
"Truncate table Sales",
|
||
"insert into Sales (sale_id, product_id, year, quantity, price) values ('1', '100', '2008', '10', '5000')",
|
||
"insert into Sales (sale_id, product_id, year, quantity, price) values ('2', '100', '2009', '12', '5000')",
|
||
"insert into Sales (sale_id, product_id, year, quantity, price) values ('7', '200', '2011', '15', '9000')",
|
||
"Truncate table Product",
|
||
"insert into Product (product_id, product_name) values ('100', 'Nokia')",
|
||
"insert into Product (product_id, product_name) values ('200', 'Apple')",
|
||
"insert into Product (product_id, product_name) values ('300', 'Samsung')"
|
||
],
|
||
"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\":{\"Sales\":[\"sale_id\",\"product_id\",\"year\",\"quantity\",\"price\"],\"Product\":[\"product_id\",\"product_name\"]},\"rows\":{\"Sales\":[[1,100,2008,10,5000],[2,100,2009,12,5000],[7,200,2011,15,9000]],\"Product\":[[100,\"Nokia\"],[200,\"Apple\"],[300,\"Samsung\"]]}}",
|
||
"__typename": "QuestionNode"
|
||
}
|
||
}
|
||
} |