1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-10-24 22:38:57 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
2025-09-29 14:43:44 +08:00
parent 2862a227c4
commit 13f2098086
4409 changed files with 168933 additions and 166256 deletions

View File

@@ -7,17 +7,17 @@
"boundTopicId": 7635,
"title": "Product Sales Analysis III",
"titleSlug": "product-sales-analysis-iii",
"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>&nbsp;</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>&nbsp;</p>\n\n<p>Write a solution to select&nbsp;the <strong>product id</strong>, <strong>year</strong>, <strong>quantity</strong>, and <strong>price</strong> for the <strong>first year</strong> of every product sold.</p>\n\n<p>Return the resulting table in <strong>any order</strong>.</p>\n\n<p>The&nbsp;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> \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_id | first_year | quantity | price |\n+------------+------------+----------+-------+ \n| 100 | 2008 | 10 | 5000 |\n| 200 | 2011 | 15 | 9000 |\n+------------+------------+----------+-------+\n</pre>\n",
"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 records a sale of a product in a given year.\nA product may have multiple sales entries in the same year.\nNote that the per-unit price.\n\n</pre>\n\n<p>Write a solution to find all sales that occurred in the <strong data-end=\"967\" data-start=\"953\">first year</strong> each product was sold.</p>\n\n<ul data-end=\"1234\" data-start=\"992\">\n\t<li data-end=\"1078\" data-start=\"992\">\n\t<p data-end=\"1078\" data-start=\"994\">For each <code data-end=\"1015\" data-start=\"1003\">product_id</code>, identify the earliest <code data-end=\"1045\" data-start=\"1039\">year</code> it appears in the <code data-end=\"1071\" data-start=\"1064\">Sales</code> table.</p>\n\t</li>\n\t<li data-end=\"1140\" data-start=\"1079\">\n\t<p data-end=\"1140\" data-start=\"1081\">Return <strong data-end=\"1095\" data-start=\"1088\">all</strong> sales entries for that product in that year.</p>\n\t</li>\n</ul>\n\n<p data-end=\"1234\" data-start=\"1143\">Return a table with the following columns: <strong>product_id</strong>,<strong> first_year</strong>, <strong>quantity, </strong>and<strong> price</strong>.<br />\nReturn the result in any order.</p>\n\n<p>&nbsp;</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+---------+------------+------+----------+-------+\n\n<strong>Output:</strong> \n+------------+------------+----------+-------+\n| product_id | first_year | quantity | price |\n+------------+------------+----------+-------+ \n| 100 | 2008 | 10 | 5000 |\n| 200 | 2011 | 15 | 9000 |\n+------------+------------+----------+-------+\n</pre>\n",
"translatedTitle": "产品销售分析 III",
"translatedContent": "<p>销售表&nbsp;<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) 是这张表的主键(具有唯一值的列的组合)。\nproduct_id 是产品表的外键reference 列)。\n这张表的每一行都表示编号 product_id 的产品在某一年的销售额。\n请注意价格是按每单位计的。\n</pre>\n\n<p>&nbsp;</p>\n\n<p>产品表&nbsp;<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这张表的每一行都标识每个产品的 id 和 产品名称。</pre>\n\n<p>&nbsp;</p>\n\n<p>编写解决方案,选出每个售出过的产品&nbsp;<strong>第一年</strong> 销售的 <strong>产品 id</strong><strong>年份</strong><strong>数量&nbsp;</strong>和 <strong>价格</strong>。</p>\n\n<p>结果表中的条目可以按 <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>\nSales 表:\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_id | first_year | quantity | price |\n+------------+------------+----------+-------+ \n| 100 | 2008 | 10 | 5000 |\n| 200 | 2011 | 15 | 9000 |\n+------------+------------+----------+-------+</pre>\n",
"translatedContent": "<p>销售表&nbsp;<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) 是这张表的主键(具有唯一值的列的组合)。\nproduct_id 是产品表的外键reference 列)。\n这张表的每一行都表示编号 product_id 的产品在某一年的销售额。\n一个产品可能在同一年内有多个销售条目。\n请注意,价格是按每单位计的。\n</pre>\n\n<p>编写解决方案,选出每个售出过的产品&nbsp;<strong>第一年</strong> 销售的 <strong>产品 id</strong>、<strong>年份</strong>、<strong>数量&nbsp;</strong>和 <strong>价格</strong>。</p>\n\n<ul>\n\t<li>对每个 <code>product_id</code>找到其在Sales表中首次出现的最早年份。</li>\n\t<li>返回该产品在该年度的 <strong>所有</strong> 销售条目。</li>\n</ul>\n\n<p>返回一张有这些列的表:<strong>product_id</strong><strong>first_year</strong><strong>quantity&nbsp;</strong>和<strong>&nbsp;price</strong>。</p>\n\n<p>结果表中的条目可以按 <strong>任意顺序</strong> 排列。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre>\n<strong>输入:</strong>\nSales 表:\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+---------+------------+------+----------+-------+\n<strong>输出:</strong>\n+------------+------------+----------+-------+\n| product_id | first_year | quantity | price |\n+------------+------------+----------+-------+ \n| 100 | 2008 | 10 | 5000 |\n| 200 | 2011 | 15 | 9000 |\n+------------+------------+----------+-------+</pre>\n",
"isPaidOnly": false,
"difficulty": "Medium",
"likes": 52,
"likes": 59,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[{\"title\": \"Product Sales Analysis II\", \"titleSlug\": \"product-sales-analysis-ii\", \"difficulty\": \"Easy\", \"translatedTitle\": \"\\u4ea7\\u54c1\\u9500\\u552e\\u5206\\u6790 II\", \"isPaidOnly\": true}, {\"title\": \"Product Sales Analysis IV\", \"titleSlug\": \"product-sales-analysis-iv\", \"difficulty\": \"Medium\", \"translatedTitle\": \"\\u4ea7\\u54c1\\u9500\\u552e\\u5206\\u6790 IV\", \"isPaidOnly\": true}, {\"title\": \"Product Sales Analysis V\", \"titleSlug\": \"product-sales-analysis-v\", \"difficulty\": \"Easy\", \"translatedTitle\": \"\\u4ea7\\u54c1\\u9500\\u552e\\u5206\\u6790\\u2164\", \"isPaidOnly\": true}]",
"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, \"cangjie\": false}",
"langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python3\": false, \"python\": false, \"javascript\": false, \"typescript\": false, \"csharp\": false, \"c\": false, \"golang\": false, \"kotlin\": false, \"swift\": false, \"rust\": false, \"ruby\": false, \"php\": false, \"dart\": false, \"scala\": false, \"elixir\": false, \"erlang\": false, \"racket\": false, \"cangjie\": false, \"bash\": false, \"html\": false, \"pythonml\": false, \"react\": false, \"vanillajs\": false, \"mysql\": false, \"mssql\": false, \"postgresql\": false, \"oraclesql\": false, \"pythondata\": false}",
"topicTags": [
{
"name": "Database",
@@ -40,6 +40,12 @@
"code": "/* Write your T-SQL query statement below */",
"__typename": "CodeSnippetNode"
},
{
"lang": "PostgreSQL",
"langSlug": "postgresql",
"code": "-- Write your PostgreSQL query statement below",
"__typename": "CodeSnippetNode"
},
{
"lang": "Oracle",
"langSlug": "oraclesql",
@@ -49,35 +55,24 @@
{
"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",
"code": "import pandas as pd\n\ndef sales_analysis(sales: pd.DataFrame) -> pd.DataFrame:\n ",
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"29.6K\", \"totalSubmission\": \"62.9K\", \"totalAcceptedRaw\": 29590, \"totalSubmissionRaw\": 62864, \"acRate\": \"47.1%\"}",
"stats": "{\"totalAccepted\": \"35.8K\", \"totalSubmission\": \"76.5K\", \"totalAcceptedRaw\": 35790, \"totalSubmissionRaw\": 76477, \"acRate\": \"46.8%\"}",
"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)\"}}}",
"sampleTestCase": "{\"headers\":{\"Sales\":[\"sale_id\",\"product_id\",\"year\",\"quantity\",\"price\"]},\"rows\":{\"Sales\":[[1,100,2008,10,5000],[2,100,2009,12,5000],[7,200,2011,15,9000]]}}",
"metaData": "{\"mysql\":[\"Create table If Not Exists Sales (sale_id int, product_id int, year int, quantity int, price int)\"],\"mssql\":[\"Create table Sales (sale_id int, product_id int, year int, quantity int, price int)\"],\"oraclesql\":[\"Create table Sales (sale_id int, product_id int, year int, quantity int, price int)\"],\"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'})\"],\"postgresql\":[\"Create table If Not Exists Sales (sale_id int, product_id int, year int, quantity int, price int)\\n\"],\"database_schema\":{\"Sales\":{\"sale_id\":\"INT\",\"product_id\":\"INT\",\"year\":\"INT\",\"quantity\":\"INT\",\"price\":\"INT\"}}}",
"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')"
"insert into Sales (sale_id, product_id, year, quantity, price) values ('7', '200', '2011', '15', '9000')"
],
"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.2.2 and NumPy 1.26.4<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>PostgreSQL 16<\\/p>\"]}",
@@ -88,7 +83,7 @@
"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\"]]}}",
"exampleTestcases": "{\"headers\":{\"Sales\":[\"sale_id\",\"product_id\",\"year\",\"quantity\",\"price\"]},\"rows\":{\"Sales\":[[1,100,2008,10,5000],[2,100,2009,12,5000],[7,200,2011,15,9000]]}}",
"__typename": "QuestionNode"
}
}