1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode/originData/trips-and-users.json

92 lines
13 KiB
JSON
Raw Normal View History

2022-03-27 18:35:17 +08:00
{
"data": {
"question": {
"questionId": "262",
"questionFrontendId": "262",
"boundTopicId": null,
"title": "Trips and Users",
"titleSlug": "trips-and-users",
"content": "<p>Table: <code>Trips</code></p>\n\n<pre>\n+-------------+----------+\n| Column Name | Type |\n+-------------+----------+\n| id | int |\n| client_id | int |\n| driver_id | int |\n| city_id | int |\n| status | enum |\n| request_at | date | \n+-------------+----------+\nid is the primary key for this table.\nThe table holds all taxi trips. Each trip has a unique id, while client_id and driver_id are foreign keys to the users_id at the Users table.\nStatus is an ENUM type of (&#39;completed&#39;, &#39;cancelled_by_driver&#39;, &#39;cancelled_by_client&#39;).\n</pre>\n\n<p>&nbsp;</p>\n\n<p>Table: <code>Users</code></p>\n\n<pre>\n+-------------+----------+\n| Column Name | Type |\n+-------------+----------+\n| users_id | int |\n| banned | enum |\n| role | enum |\n+-------------+----------+\nusers_id is the primary key for this table.\nThe table holds all users. Each user has a unique users_id, and role is an ENUM type of (&#39;client&#39;, &#39;driver&#39;, &#39;partner&#39;).\nbanned is an ENUM type of (&#39;Yes&#39;, &#39;No&#39;).\n</pre>\n\n<p>&nbsp;</p>\n\n<p>The <strong>cancellation rate</strong> is computed by dividing the number of canceled (by client or driver) requests with unbanned users by the total number of requests with unbanned users on that day.</p>\n\n<p>Write a SQL query to find the <strong>cancellation rate</strong> of requests with unbanned users (<strong>both client and driver must not be banned</strong>) each day between <code>&quot;2013-10-01&quot;</code> and <code>&quot;2013-10-03&quot;</code>. Round <code>Cancellation Rate</code> to <strong>two decimal</strong> points.</p>\n\n<p>Return the result table in <strong>any order</strong>.</p>\n\n<p>The query result format is in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong>Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \nTrips table:\n+----+-----------+-----------+---------+---------------------+------------+\n| id | client_id | driver_id | city_id | status | request_at |\n+----+-----------+-----------+---------+---------------------+------------+\n| 1 | 1 | 10 | 1 | completed | 2013-10-01 |\n| 2 | 2 | 11 | 1 | cancelled_by_driver | 2013-10-01 |\n| 3 | 3 | 12 | 6 | completed | 2013-10-01 |\n| 4 | 4 | 13 | 6 | cancelled_by_client | 2013-10-01 |\n| 5 | 1 | 10 | 1 | completed | 2013-10-02 |\n| 6 | 2 | 11 | 6 | completed | 2013-10-02 |\n| 7 | 3 | 12 | 6 | completed | 2013-10-02 |\n| 8 | 2 | 12 | 12 | completed | 2013-10-03 |\n| 9 | 3 | 10 | 12 | completed | 2013-10-03 |\n| 10 | 4 | 13 | 12 | cancelled_by_driver | 2013-10-03 |\n+----+-----------+-----------+---------+---------------------+------------+\nUsers table:\n+----------+--------+--------+\n| users_id | banned | role |\n+----------+--------+--------+\n| 1 | No | client |\n| 2 | Yes | client |\n| 3 | No | client |\n| 4 | No | client |\n| 10 | No | driver |\n| 11 | No | driver |\n| 12 | No | driver |\n| 13 | No | driver |\n+----------+--------+--------+\n<strong>Output:</strong> \n+------------+-------------------+\n| Day | Cancellation Rate |\n+------------+-------------------+\n| 2013-10-01 | 0.33 |\n| 2013-10-02 | 0.00 |\n| 2013-10-03 | 0.50 |\n+------------+-------------------+\n<strong>Explanation:</strong> \nOn 2013-10-01:\n - There were 4 requests in total, 2 of which were canceled.\n - However, the request with Id=2 was made by a banned client (User_Id=2), so it is ignored in the calculation.\n - Hence there are 3 unbanned requests in total, 1 of which was canceled.\n - The Cancellation Rate is (1 / 3) = 0.33\nOn 2013-10-02:\n - There w
"translatedTitle": null,
"translatedContent": null,
"isPaidOnly": false,
"difficulty": "Hard",
2022-05-02 23:44:12 +08:00
"likes": 712,
"dislikes": 460,
2022-03-27 18:35:17 +08:00
"isLiked": null,
"similarQuestions": "[{\"title\": \"Hopper Company Queries I\", \"titleSlug\": \"hopper-company-queries-i\", \"difficulty\": \"Hard\", \"translatedTitle\": null}, {\"title\": \"Hopper Company Queries II\", \"titleSlug\": \"hopper-company-queries-ii\", \"difficulty\": \"Hard\", \"translatedTitle\": null}, {\"title\": \"Hopper Company Queries III\", \"titleSlug\": \"hopper-company-queries-iii\", \"difficulty\": \"Hard\", \"translatedTitle\": null}]",
"exampleTestcases": "{\"headers\": {\"Trips\": [\"id\", \"client_id\", \"driver_id\", \"city_id\", \"status\", \"request_at\"], \"Users\": [\"users_id\", \"banned\", \"role\"]}, \"rows\": {\"Trips\": [[\"1\", \"1\", \"10\", \"1\", \"completed\", \"2013-10-01\"], [\"2\", \"2\", \"11\", \"1\", \"cancelled_by_driver\", \"2013-10-01\"], [\"3\", \"3\", \"12\", \"6\", \"completed\", \"2013-10-01\"], [\"4\", \"4\", \"13\", \"6\", \"cancelled_by_client\", \"2013-10-01\"], [\"5\", \"1\", \"10\", \"1\", \"completed\", \"2013-10-02\"], [\"6\", \"2\", \"11\", \"6\", \"completed\", \"2013-10-02\"], [\"7\", \"3\", \"12\", \"6\", \"completed\", \"2013-10-02\"], [\"8\", \"2\", \"12\", \"12\", \"completed\", \"2013-10-03\"], [\"9\", \"3\", \"10\", \"12\", \"completed\", \"2013-10-03\"], [\"10\", \"4\", \"13\", \"12\", \"cancelled_by_driver\", \"2013-10-03\"]], \"Users\": [[\"1\", \"No\", \"client\"], [\"2\", \"Yes\", \"client\"], [\"3\", \"No\", \"client\"], [\"4\", \"No\", \"client\"], [\"10\", \"No\", \"driver\"], [\"11\", \"No\", \"driver\"], [\"12\", \"No\", \"driver\"], [\"13\", \"No\", \"driver\"]]}}",
"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"
}
],
2022-05-02 23:44:12 +08:00
"stats": "{\"totalAccepted\": \"113.4K\", \"totalSubmission\": \"300.4K\", \"totalAcceptedRaw\": 113430, \"totalSubmissionRaw\": 300386, \"acRate\": \"37.8%\"}",
2022-03-27 18:35:17 +08:00
"hints": [],
"solution": null,
"status": null,
"sampleTestCase": "{\"headers\": {\"Trips\": [\"id\", \"client_id\", \"driver_id\", \"city_id\", \"status\", \"request_at\"], \"Users\": [\"users_id\", \"banned\", \"role\"]}, \"rows\": {\"Trips\": [[\"1\", \"1\", \"10\", \"1\", \"completed\", \"2013-10-01\"], [\"2\", \"2\", \"11\", \"1\", \"cancelled_by_driver\", \"2013-10-01\"], [\"3\", \"3\", \"12\", \"6\", \"completed\", \"2013-10-01\"], [\"4\", \"4\", \"13\", \"6\", \"cancelled_by_client\", \"2013-10-01\"], [\"5\", \"1\", \"10\", \"1\", \"completed\", \"2013-10-02\"], [\"6\", \"2\", \"11\", \"6\", \"completed\", \"2013-10-02\"], [\"7\", \"3\", \"12\", \"6\", \"completed\", \"2013-10-02\"], [\"8\", \"2\", \"12\", \"12\", \"completed\", \"2013-10-03\"], [\"9\", \"3\", \"10\", \"12\", \"completed\", \"2013-10-03\"], [\"10\", \"4\", \"13\", \"12\", \"cancelled_by_driver\", \"2013-10-03\"]], \"Users\": [[\"1\", \"No\", \"client\"], [\"2\", \"Yes\", \"client\"], [\"3\", \"No\", \"client\"], [\"4\", \"No\", \"client\"], [\"10\", \"No\", \"driver\"], [\"11\", \"No\", \"driver\"], [\"12\", \"No\", \"driver\"], [\"13\", \"No\", \"driver\"]]}}",
"metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Trips (id int, client_id int, driver_id int, city_id int, status ENUM('completed', 'cancelled_by_driver', 'cancelled_by_client'), request_at varchar(50))\",\n \"Create table If Not Exists Users (users_id int, banned varchar(50), role ENUM('client', 'driver', 'partner'))\"\n ],\n \"mssql\": [\n \"Create table Trips (id int, client_id int, driver_id int, city_id int, status VARCHAR(20) NOT NULL CHECK (status IN ('completed', 'cancelled_by_driver', 'cancelled_by_client')), request_at varchar(50))\",\n \"Create table Users (users_id int, banned varchar(50), role VARCHAR(10) NOT NULL CHECK (role IN ('client', 'driver', 'partner')))\"\n ],\n \"oraclesql\": [\n \"Create table Trips (id int, client_id int, driver_id int, city_id int, status VARCHAR(20) NOT NULL CHECK (status IN ('completed', 'cancelled_by_driver', 'cancelled_by_client')), request_at varchar(50))\",\n \"Create table Users (users_id int, banned varchar(50), role VARCHAR(10) NOT NULL CHECK (role IN ('client', 'driver', 'partner')))\"\n ],\n \"database\": true\n}",
"judgerAvailable": true,
"judgeType": "large",
"mysqlSchemas": [
"Create table If Not Exists Trips (id int, client_id int, driver_id int, city_id int, status ENUM('completed', 'cancelled_by_driver', 'cancelled_by_client'), request_at varchar(50))",
"Create table If Not Exists Users (users_id int, banned varchar(50), role ENUM('client', 'driver', 'partner'))",
"Truncate table Trips",
"insert into Trips (id, client_id, driver_id, city_id, status, request_at) values ('1', '1', '10', '1', 'completed', '2013-10-01')",
"insert into Trips (id, client_id, driver_id, city_id, status, request_at) values ('2', '2', '11', '1', 'cancelled_by_driver', '2013-10-01')",
"insert into Trips (id, client_id, driver_id, city_id, status, request_at) values ('3', '3', '12', '6', 'completed', '2013-10-01')",
"insert into Trips (id, client_id, driver_id, city_id, status, request_at) values ('4', '4', '13', '6', 'cancelled_by_client', '2013-10-01')",
"insert into Trips (id, client_id, driver_id, city_id, status, request_at) values ('5', '1', '10', '1', 'completed', '2013-10-02')",
"insert into Trips (id, client_id, driver_id, city_id, status, request_at) values ('6', '2', '11', '6', 'completed', '2013-10-02')",
"insert into Trips (id, client_id, driver_id, city_id, status, request_at) values ('7', '3', '12', '6', 'completed', '2013-10-02')",
"insert into Trips (id, client_id, driver_id, city_id, status, request_at) values ('8', '2', '12', '12', 'completed', '2013-10-03')",
"insert into Trips (id, client_id, driver_id, city_id, status, request_at) values ('9', '3', '10', '12', 'completed', '2013-10-03')",
"insert into Trips (id, client_id, driver_id, city_id, status, request_at) values ('10', '4', '13', '12', 'cancelled_by_driver', '2013-10-03')",
"Truncate table Users",
"insert into Users (users_id, banned, role) values ('1', 'No', 'client')",
"insert into Users (users_id, banned, role) values ('2', 'Yes', 'client')",
"insert into Users (users_id, banned, role) values ('3', 'No', 'client')",
"insert into Users (users_id, banned, role) values ('4', 'No', 'client')",
"insert into Users (users_id, banned, role) values ('10', 'No', 'driver')",
"insert into Users (users_id, banned, role) values ('11', 'No', 'driver')",
"insert into Users (users_id, banned, role) values ('12', 'No', 'driver')",
"insert into Users (users_id, banned, role) values ('13', 'No', 'driver')"
],
"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>\"]}",
"libraryUrl": null,
"adminUrl": null,
"challengeQuestion": null,
"__typename": "QuestionNode"
}
}
}