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/rearrange-products-table.json
2023-12-09 19:57:46 +08:00

89 lines
9.0 KiB
JSON
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{
"data": {
"question": {
"questionId": "1948",
"questionFrontendId": "1795",
"categoryTitle": "Database",
"boundTopicId": 669283,
"title": "Rearrange Products Table",
"titleSlug": "rearrange-products-table",
"content": "<p>Table: <code>Products</code></p>\n\n<pre>\n+-------------+---------+\n| Column Name | Type |\n+-------------+---------+\n| product_id | int |\n| store1 | int |\n| store2 | int |\n| store3 | int |\n+-------------+---------+\nproduct_id is the primary key (column with unique values) for this table.\nEach row in this table indicates the product&#39;s price in 3 different stores: store1, store2, and store3.\nIf the product is not available in a store, the price will be null in that store&#39;s column.\n</pre>\n\n<p>&nbsp;</p>\n\n<p>Write a solution to rearrange the <code>Products</code> table so that each row has <code>(product_id, store, price)</code>. If a product is not available in a store, do <strong>not</strong> include a row with that <code>product_id</code> and <code>store</code> combination in the result table.</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>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \nProducts table:\n+------------+--------+--------+--------+\n| product_id | store1 | store2 | store3 |\n+------------+--------+--------+--------+\n| 0 | 95 | 100 | 105 |\n| 1 | 70 | null | 80 |\n+------------+--------+--------+--------+\n<strong>Output:</strong> \n+------------+--------+-------+\n| product_id | store | price |\n+------------+--------+-------+\n| 0 | store1 | 95 |\n| 0 | store2 | 100 |\n| 0 | store3 | 105 |\n| 1 | store1 | 70 |\n| 1 | store3 | 80 |\n+------------+--------+-------+\n<strong>Explanation:</strong> \nProduct 0 is available in all three stores with prices 95, 100, and 105 respectively.\nProduct 1 is available in store1 with price 70 and store3 with price 80. The product is not available in store2.\n</pre>\n",
"translatedTitle": "每个产品在不同商店的价格",
"translatedContent": "<p>表:<code>Products</code></p>\n\n<pre>\n+-------------+---------+\n| Column Name | Type |\n+-------------+---------+\n| product_id | int |\n| store1 | int |\n| store2 | int |\n| store3 | int |\n+-------------+---------+\n在 SQL 中,这张表的主键是 product_id产品Id。\n每行存储了这一产品在不同商店 store1, store2, store3 的价格。\n如果这一产品在商店里没有出售则值将为 null。\n</pre>\n\n<p>&nbsp;</p>\n\n<p>请你重构 <code>Products</code> 表,查询每个产品在不同商店的价格,使得输出的格式变为<code>(product_id, store, price)</code> 。如果这一产品在商店里没有出售,则不输出这一行。</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>\nProducts table:\n+------------+--------+--------+--------+\n| product_id | store1 | store2 | store3 |\n+------------+--------+--------+--------+\n| 0 | 95 | 100 | 105 |\n| 1 | 70 | null | 80 |\n+------------+--------+--------+--------+\n<strong>输出:</strong>\n+------------+--------+-------+\n| product_id | store | price |\n+------------+--------+-------+\n| 0 | store1 | 95 |\n| 0 | store2 | 100 |\n| 0 | store3 | 105 |\n| 1 | store1 | 70 |\n| 1 | store3 | 80 |\n+------------+--------+-------+\n<strong>解释:</strong>\n产品 0 在 store1、store2、store3 的价格分别为 95、100、105。\n产品 1 在 store1、store3 的价格分别为 70、80。在 store2 无法买到。</pre>\n",
"isPaidOnly": false,
"difficulty": "Easy",
"likes": 157,
"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 rearrange_products_table(products: pd.DataFrame) -> pd.DataFrame:\n ",
"__typename": "CodeSnippetNode"
},
{
"lang": "PostgreSQL",
"langSlug": "postgresql",
"code": "-- Write your PostgreSQL query statement below",
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"46.8K\", \"totalSubmission\": \"59.8K\", \"totalAcceptedRaw\": 46790, \"totalSubmissionRaw\": 59821, \"acRate\": \"78.2%\"}",
"hints": [],
"solution": null,
"status": null,
"sampleTestCase": "{\"headers\":{\"Products\":[\"product_id\",\"store1\",\"store2\",\"store3\"]},\"rows\":{\"Products\":[[0, 95, 100, 105], [1, 70, null, 80]]}}",
"metaData": "{\"mysql\":[\"Create table If Not Exists Products (product_id int, store1 int, store2 int, store3 int)\"],\"mssql\":[\"Create table Products (product_id int, store1 int, store2 int, store3 int)\"],\"oraclesql\":[\"Create table Products (product_id int, store1 int, store2 int, store3 int)\"],\"database\":true,\"name\":\"rearrange_products_table\",\"pythondata\":[\"Products = pd.DataFrame([], columns=['product_id', 'store1', 'store2', 'store3']).astype({'product_id':'Int64', 'store1':'Int64', 'store2':'Int64', 'store3':'Int64'})\"],\"manual\":false,\"postgresql\":[\"Create table If Not Exists Products (product_id int, store1 int, store2 int, store3 int)\\n\"],\"database_schema\":{\"Products\":{\"product_id\":\"INT\",\"store1\":\"INT\",\"store2\":\"INT\",\"store3\":\"INT\"}}}",
"judgerAvailable": true,
"judgeType": "large",
"mysqlSchemas": [
"Create table If Not Exists Products (product_id int, store1 int, store2 int, store3 int)",
"Truncate table Products",
"insert into Products (product_id, store1, store2, store3) values ('0', '95', '100', '105')",
"insert into Products (product_id, store1, store2, store3) values ('1', '70', 'None', '80')"
],
"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\":{\"Products\":[\"product_id\",\"store1\",\"store2\",\"store3\"]},\"rows\":{\"Products\":[[0, 95, 100, 105], [1, 70, null, 80]]}}",
"__typename": "QuestionNode"
}
}
}