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/originData/market-analysis-i.json
2023-12-09 19:57:46 +08:00

109 lines
12 KiB
JSON

{
"data": {
"question": {
"questionId": "1268",
"questionFrontendId": "1158",
"boundTopicId": null,
"title": "Market Analysis I",
"titleSlug": "market-analysis-i",
"content": "<p>Table: <code>Users</code></p>\n\n<pre>\n+----------------+---------+\n| Column Name | Type |\n+----------------+---------+\n| user_id | int |\n| join_date | date |\n| favorite_brand | varchar |\n+----------------+---------+\nuser_id is the primary key (column with unique values) of this table.\nThis table has the info of the users of an online shopping website where users can sell and buy items.\n</pre>\n\n<p>&nbsp;</p>\n\n<p>Table: <code>Orders</code></p>\n\n<pre>\n+---------------+---------+\n| Column Name | Type |\n+---------------+---------+\n| order_id | int |\n| order_date | date |\n| item_id | int |\n| buyer_id | int |\n| seller_id | int |\n+---------------+---------+\norder_id is the primary key (column with unique values) of this table.\nitem_id is a foreign key (reference column) to the Items table.\nbuyer_id and seller_id are foreign keys to the Users table.\n</pre>\n\n<p>&nbsp;</p>\n\n<p>Table: <code>Items</code></p>\n\n<pre>\n+---------------+---------+\n| Column Name | Type |\n+---------------+---------+\n| item_id | int |\n| item_brand | varchar |\n+---------------+---------+\nitem_id is the primary key (column with unique values) of this table.\n</pre>\n\n<p>&nbsp;</p>\n\n<p>Write a solution&nbsp;to find for each user, the join date and the number of orders they made as a buyer in <code>2019</code>.</p>\n\n<p>Return the result 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> \nUsers table:\n+---------+------------+----------------+\n| user_id | join_date | favorite_brand |\n+---------+------------+----------------+\n| 1 | 2018-01-01 | Lenovo |\n| 2 | 2018-02-09 | Samsung |\n| 3 | 2018-01-19 | LG |\n| 4 | 2018-05-21 | HP |\n+---------+------------+----------------+\nOrders table:\n+----------+------------+---------+----------+-----------+\n| order_id | order_date | item_id | buyer_id | seller_id |\n+----------+------------+---------+----------+-----------+\n| 1 | 2019-08-01 | 4 | 1 | 2 |\n| 2 | 2018-08-02 | 2 | 1 | 3 |\n| 3 | 2019-08-03 | 3 | 2 | 3 |\n| 4 | 2018-08-04 | 1 | 4 | 2 |\n| 5 | 2018-08-04 | 1 | 3 | 4 |\n| 6 | 2019-08-05 | 2 | 2 | 4 |\n+----------+------------+---------+----------+-----------+\nItems table:\n+---------+------------+\n| item_id | item_brand |\n+---------+------------+\n| 1 | Samsung |\n| 2 | Lenovo |\n| 3 | LG |\n| 4 | HP |\n+---------+------------+\n<strong>Output:</strong> \n+-----------+------------+----------------+\n| buyer_id | join_date | orders_in_2019 |\n+-----------+------------+----------------+\n| 1 | 2018-01-01 | 1 |\n| 2 | 2018-02-09 | 2 |\n| 3 | 2018-01-19 | 0 |\n| 4 | 2018-05-21 | 0 |\n+-----------+------------+----------------+\n</pre>\n",
"translatedTitle": null,
"translatedContent": null,
"isPaidOnly": false,
"difficulty": "Medium",
"likes": 607,
"dislikes": 64,
"isLiked": null,
"similarQuestions": "[]",
"exampleTestcases": "{\"headers\":{\"Users\":[\"user_id\",\"join_date\",\"favorite_brand\"],\"Orders\":[\"order_id\",\"order_date\",\"item_id\",\"buyer_id\",\"seller_id\"],\"Items\":[\"item_id\",\"item_brand\"]},\"rows\":{\"Users\":[[1,\"2018-01-01\",\"Lenovo\"],[2,\"2018-02-09\",\"Samsung\"],[3,\"2018-01-19\",\"LG\"],[4,\"2018-05-21\",\"HP\"]],\"Orders\":[[1,\"2019-08-01\",4,1,2],[2,\"2018-08-02\",2,1,3],[3,\"2019-08-03\",3,2,3],[4,\"2018-08-04\",1,4,2],[5,\"2018-08-04\",1,3,4],[6,\"2019-08-05\",2,2,4]],\"Items\":[[1,\"Samsung\"],[2,\"Lenovo\"],[3,\"LG\"],[4,\"HP\"]]}}",
"categoryTitle": "Database",
"contributors": [],
"topicTags": [
{
"name": "Database",
"slug": "database",
"translatedName": null,
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": [
{
"lang": "MySQL",
"langSlug": "mysql",
"code": "# Write your MySQL query statement below\n",
"__typename": "CodeSnippetNode"
},
{
"lang": "MS SQL Server",
"langSlug": "mssql",
"code": "/* Write your T-SQL query statement below */\n",
"__typename": "CodeSnippetNode"
},
{
"lang": "Oracle",
"langSlug": "oraclesql",
"code": "/* Write your PL/SQL query statement below */\n",
"__typename": "CodeSnippetNode"
},
{
"lang": "Pandas",
"langSlug": "pythondata",
"code": "import pandas as pd\n\ndef market_analysis(users: pd.DataFrame, orders: pd.DataFrame, items: pd.DataFrame) -> pd.DataFrame:\n ",
"__typename": "CodeSnippetNode"
},
{
"lang": "PostgreSQL",
"langSlug": "postgresql",
"code": "-- Write your PostgreSQL query statement below\n",
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"90.7K\", \"totalSubmission\": \"158.5K\", \"totalAcceptedRaw\": 90653, \"totalSubmissionRaw\": 158464, \"acRate\": \"57.2%\"}",
"hints": [],
"solution": {
"id": "2056",
"canSeeDetail": true,
"paidOnly": false,
"hasVideoSolution": false,
"paidOnlyVideo": true,
"__typename": "ArticleNode"
},
"status": null,
"sampleTestCase": "{\"headers\":{\"Users\":[\"user_id\",\"join_date\",\"favorite_brand\"],\"Orders\":[\"order_id\",\"order_date\",\"item_id\",\"buyer_id\",\"seller_id\"],\"Items\":[\"item_id\",\"item_brand\"]},\"rows\":{\"Users\":[[1,\"2018-01-01\",\"Lenovo\"],[2,\"2018-02-09\",\"Samsung\"],[3,\"2018-01-19\",\"LG\"],[4,\"2018-05-21\",\"HP\"]],\"Orders\":[[1,\"2019-08-01\",4,1,2],[2,\"2018-08-02\",2,1,3],[3,\"2019-08-03\",3,2,3],[4,\"2018-08-04\",1,4,2],[5,\"2018-08-04\",1,3,4],[6,\"2019-08-05\",2,2,4]],\"Items\":[[1,\"Samsung\"],[2,\"Lenovo\"],[3,\"LG\"],[4,\"HP\"]]}}",
"metaData": "{\"mysql\": [\"Create table If Not Exists Users (user_id int, join_date date, favorite_brand varchar(10))\", \"Create table If Not Exists Orders (order_id int, order_date date, item_id int, buyer_id int, seller_id int)\", \"Create table If Not Exists Items (item_id int, item_brand varchar(10))\"], \"mssql\": [\"Create table Users (user_id int, join_date date, favorite_brand varchar(10))\", \"Create table Orders (order_id int, order_date date, item_id int, buyer_id int, seller_id int)\", \"Create table Items (item_id int, item_brand varchar(10))\"], \"oraclesql\": [\"Create table Users (user_id int, join_date date, favorite_brand varchar(10))\", \"Create table Orders (order_id int, order_date date, item_id int, buyer_id int, seller_id int)\", \"Create table Items (item_id int, item_brand varchar(10))\", \"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"], \"database\": true, \"name\": \"market_analysis\", \"pythondata\": [\"Users = pd.DataFrame([], columns=['user_id', 'join_date', 'favorite_brand']).astype({'user_id':'Int64', 'join_date':'datetime64[ns]', 'favorite_brand':'object'})\", \"Orders = pd.DataFrame([], columns=['order_id', 'order_date', 'item_id', 'buyer_id', 'seller_id']).astype({'order_id':'Int64', 'order_date':'datetime64[ns]', 'item_id':'Int64', 'buyer_id':'Int64', 'seller_id':'Int64'})\", \"Items = pd.DataFrame([], columns=['item_id', 'item_brand']).astype({'item_id':'Int64', 'item_brand':'object'})\"], \"postgresql\": [\"\\nCreate table If Not Exists Users (user_id int, join_date date, favorite_brand varchar(10))\", \"Create table If Not Exists Orders (order_id int, order_date date, item_id int, buyer_id int, seller_id int)\", \"Create table If Not Exists Items (item_id int, item_brand varchar(10))\"], \"database_schema\": {\"Users\": {\"user_id\": \"INT\", \"join_date\": \"DATE\", \"favorite_brand\": \"VARCHAR(10)\"}, \"Orders\": {\"order_id\": \"INT\", \"order_date\": \"DATE\", \"item_id\": \"INT\", \"buyer_id\": \"INT\", \"seller_id\": \"INT\"}, \"Items\": {\"item_id\": \"INT\", \"item_brand\": \"VARCHAR(10)\"}}}",
"judgerAvailable": true,
"judgeType": "large",
"mysqlSchemas": [
"Create table If Not Exists Users (user_id int, join_date date, favorite_brand varchar(10))",
"Create table If Not Exists Orders (order_id int, order_date date, item_id int, buyer_id int, seller_id int)",
"Create table If Not Exists Items (item_id int, item_brand varchar(10))",
"Truncate table Users",
"insert into Users (user_id, join_date, favorite_brand) values ('1', '2018-01-01', 'Lenovo')",
"insert into Users (user_id, join_date, favorite_brand) values ('2', '2018-02-09', 'Samsung')",
"insert into Users (user_id, join_date, favorite_brand) values ('3', '2018-01-19', 'LG')",
"insert into Users (user_id, join_date, favorite_brand) values ('4', '2018-05-21', 'HP')",
"Truncate table Orders",
"insert into Orders (order_id, order_date, item_id, buyer_id, seller_id) values ('1', '2019-08-01', '4', '1', '2')",
"insert into Orders (order_id, order_date, item_id, buyer_id, seller_id) values ('2', '2018-08-02', '2', '1', '3')",
"insert into Orders (order_id, order_date, item_id, buyer_id, seller_id) values ('3', '2019-08-03', '3', '2', '3')",
"insert into Orders (order_id, order_date, item_id, buyer_id, seller_id) values ('4', '2018-08-04', '1', '4', '2')",
"insert into Orders (order_id, order_date, item_id, buyer_id, seller_id) values ('5', '2018-08-04', '1', '3', '4')",
"insert into Orders (order_id, order_date, item_id, buyer_id, seller_id) values ('6', '2019-08-05', '2', '2', '4')",
"Truncate table Items",
"insert into Items (item_id, item_brand) values ('1', 'Samsung')",
"insert into Items (item_id, item_brand) values ('2', 'Lenovo')",
"insert into Items (item_id, item_brand) values ('3', 'LG')",
"insert into Items (item_id, item_brand) values ('4', 'HP')"
],
"enableRunCode": true,
"enableTestMode": false,
"enableDebugger": false,
"envInfo": "{\"mysql\": [\"MySQL\", \"<p><code>MySQL 8.0</code>.</p>\"], \"mssql\": [\"MS SQL Server\", \"<p><code>mssql server 2019</code>.</p>\"], \"oraclesql\": [\"Oracle\", \"<p><code>Oracle Sql 11.2</code>.</p>\"], \"pythondata\": [\"Pandas\", \"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0</p>\"], \"postgresql\": [\"PostgreSQL\", \"<p>PostgreSQL 16</p>\"]}",
"libraryUrl": null,
"adminUrl": null,
"challengeQuestion": null,
"__typename": "QuestionNode"
}
}
}