2022-03-27 20:56:26 +08:00
{
"data" : {
"question" : {
"questionId" : "262" ,
"questionFrontendId" : "262" ,
"categoryTitle" : "Database" ,
"boundTopicId" : 1331 ,
"title" : "Trips and Users" ,
"titleSlug" : "trips-and-users" ,
2023-12-09 18:42:21 +08:00
"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 (column with unique values) 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 (category) type of ('completed', 'cancelled_by_driver', 'cancelled_by_client').\n</pre>\n\n<p> </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 (column with unique values) for this table.\nThe table holds all users. Each user has a unique users_id, and role is an ENUM type of ('client', 'driver', 'partner').\nbanned is an ENUM (category) type of ('Yes', 'No').\n</pre>\n\n<p> </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 solution 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>"2013-10-01"</code> and <code>"2013-10-03"</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 result format is in the following example.</p>\n\n<p> </p>\n<p><strong class=\"example\" > E x a m p l e 1 : < / s t r o n g > < / p > \ n \ n < p r e > \ n < s t r o n g > I n p u t : < / s t r o n g > \ n T r i p s t a b l e : \ n + - - - - + - - - - - - - - - - - + - - - - - - - - - - - + - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - + \ n | i d | c l i e n t _ i d | d r i v e r _ i d | c i t y _ i d | s t a t u s | r e q u e s t _ a t | \ n + - - - - + - - - - - - - - - - - + - - - - - - - - - - - + - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - + \ n | 1 | 1 | 10 | 1 | c o m p l e t e d | 2013 -10 -0 1 | \ n | 2 | 2 | 11 | 1 | c a n c e l l e d _ b y _ d r i v e r | 2013 -10 -0 1 | \ n | 3 | 3 | 12 | 6 | c o m p l e t e d | 2013 -10 -0 1 | \ n | 4 | 4 | 13 | 6 | c a n c e l l e d _ b y _ c l i e n t | 2013 -10 -0 1 | \ n | 5 | 1 | 10 | 1 | c o m p l e t e d | 2013 -10 -0 2 | \ n | 6 | 2 | 11 | 6 | c o m p l e t e d | 2013 -10 -0 2 | \ n | 7 | 3 | 12 | 6 | c o m p l e t e d | 2013 -10 -0 2 | \ n | 8 | 2 | 12 | 12 | c o m p l e t e d | 2013 -10 -0 3 | \ n | 9 | 3 | 10 | 12 | c o m p l e t e d | 2013 -10 -0 3 | \ n | 10 | 4 | 13 | 12 | c a n c e l l e d _ b y _ d r i v e r | 2013 -10 -0 3 | \ n + - - - - + - - - - - - - - - - - + - - - - - - - - - - - + - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - + \ n U s e r s t a b l e : \ n + - - - - - - - - - - + - - - - - - - - + - - - - - - - - + \ n | u s e r s _ i d | b a n n e d | r o l e | \ n + - - - - - - - - - - + - - - - - - - - + - - - - - - - - + \ n | 1 | N o | c l i e n t | \ n | 2 | Y e s | c l i e n t | \ n | 3 | N o | c l i e n t | \ n | 4 | N o | c l i e n t | \ n | 10 | N o | d r i v e r | \ n | 11 | N o | d r i v e r | \ n | 12 | N o | d r i v e r | \ n | 13 | N o | d r i v e r | \ n + - - - - - - - - - - + - - - - - - - - + - - - - - - - - + \ n < s t r o n g > O u t p u t : < / s t r o n g > \ n + - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - + \ n | D a y | C a n c e l l a t i o n R a t e | \ n + - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - + \ n | 2013 -10 -0 1 | 0.33 | \ n | 2013 -10 -0 2 | 0.00 | \ n | 2013 -10 -0 3 | 0.50 | \ n + - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - + \ n < s t r o n g > E x p l a n a t i o n : < / s t r o n g > \ n O n 2013 -10 -0 1 : \ n - T h e r e w e r e 4 r e q u e s t s i n t o t a l , 2 o f w h i c h w e r e c a n c e l e d . \ n - H o w e v e r , t h e r e q u e s t w i t h I d = 2 w a s m a d e b y a b a n n e d c l i e n t ( U s e r _ I d = 2 ) , s o i t i s i g n o r e d i n t h e c a l c u l a t i o n . \ n - H e n c e t h e r e a r e 3 u n b a n n e d r e q u e s t s i n t o t a l , 1 o f
2022-03-27 20:56:26 +08:00
"translatedTitle" : "行程和用户" ,
2023-12-09 18:42:21 +08:00
"translatedContent" : "表:<code>Trips</code>\n<div class=\"original__bRMd\">\n<div>\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 是这张表的主键(具有唯一值的列)。\n这张表中存所有出租车的行程信息。每段行程有唯一 id ,其中 client_id 和 driver_id 是 Users 表中 users_id 的外键。\nstatus 是一个表示行程状态的枚举类型,枚举成员为(‘ completed’ , ‘ cancelled_by_driver’ , ‘ cancelled_by_client’ ) 。\n</pre>\n\n<p> </p>\n\n<div class=\"original__bRMd\">\n<div>\n<p>表:<code>Users</code></p>\n</div>\n</div>\n\n<pre>\n+-------------+----------+\n| Column Name | Type |\n+-------------+----------+\n| users_id | int |\n| banned | enum |\n| role | enum |\n+-------------+----------+\nusers_id 是这张表的主键(具有唯一值的列)。\n这张表中存所有用户, 每个用户都有一个唯一的 users_id , role 是一个表示用户身份的枚举类型,枚举成员为 (‘ client’ , ‘ driver’ , ‘ partner’ ) 。\nbanned 是一个表示用户是否被禁止的枚举类型,枚举成员为 (‘ Yes’ , ‘ No’ ) 。\n</pre>\n\n<p> </p>\n\n<p><strong>取消率</strong> 的计算方式如下:(被司机或乘客取消的非禁止用户生成的订单数量) / (非禁止用户生成的订单总数)。</p>\n\n<p>编写解决方案找出 <code>\"2013-10-01\"</code><strong> </strong>至 <code>\"2013-10-03\" < / c o d e > < s t r o n g > & n b s p ; < / s t r o n g > 期 间 非 禁 止 用 户 ( < s t r o n g > 乘 客 和 司 机 都 必 须 未 被 禁 止 < / s t r o n g > ) 的 取 消 率 。 非 禁 止 用 户 即 b a n n e d 为 N o 的 用 户 , 禁 止 用 户 即 b a n n e d 为 Y e s 的 用 户 。 其 中 取 消 率 < c o d e > C a n c e l l a t i o n R a t e < / c o d e > 需 要 四 舍 五 入 保 留 < s t r o n g > 两 位 小 数 < / s t r o n g > 。 < / p > \ n \ n < p > 返 回 结 果 表 中 的 数 据 < s t r o n g > 无 顺 序 要 求 < / s t r o n g > 。 < / p > \ n \ n < p > 结 果 格 式 如 下 例 所 示 。 < / p > \ n \ n < p > & n b s p ; < / p > \ n \ n < p > < s t r o n g > 示 例 1 : < / s t r o n g > < / p > \ n \ n < p r e > \ n < s t r o n g > 输 入 : < / s t r o n g > \ n T r i p s 表 : \ n + - - - - + - - - - - - - - - - - + - - - - - - - - - - - + - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - + \ n | i d | c l i e n t _ i d | d r i v e r _ i d | c i t y _ i d | s t a t u s | r e q u e s t _ a t | \ n + - - - - + - - - - - - - - - - - + - - - - - - - - - - - + - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - + \ n | 1 | 1 | 10 | 1 | c o m p l e t e d | 2013 -10 -0 1 | \ n | 2 | 2 | 11 | 1 | c a n c e l l e d _ b y _ d r i v e r | 2013 -10 -0 1 | \ n | 3 | 3 | 12 | 6 | c o m p l e t e d | 2013 -10 -0 1 | \ n | 4 | 4 | 13 | 6 | c a n c e l l e d _ b y _ c l i e n t | 2013 -10 -0 1 | \ n | 5 | 1 | 10 | 1 | c o m p l e t e d | 2013 -10 -0 2 | \ n | 6 | 2 | 11 | 6 | c o m p l e t e d | 2013 -10 -0 2 | \ n | 7 | 3 | 12 | 6 | c o m p l e t e d | 2013 -10 -0 2 | \ n | 8 | 2 | 12 | 12 | c o m p l e t e d | 2013 -10 -0 3 | \ n | 9 | 3 | 10 | 12 | c o m p l e t e d | 2013 -10 -0 3 | \ n | 10 | 4 | 13 | 12 | c a n c e l l e d _ b y _ d r i v e r | 2013 -10 -0 3 | \ n + - - - - + - - - - - - - - - - - + - - - - - - - - - - - + - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - + \ n U s e r s 表 : \ n + - - - - - - - - - - + - - - - - - - - + - - - - - - - - + \ n | u s e r s _ i d | b a n n e d | r o l e | \ n + - - - - - - - - - - + - - - - - - - - + - - - - - - - - + \ n | 1 | N o | c l i e n t | \ n | 2 | Y e s | c l i e n t | \ n | 3 | N o | c l i e n t | \ n | 4 | N o | c l i e n t | \ n | 10 | N o | d r i v e r | \ n | 11 | N o | d r i v e r | \ n | 12 | N o | d r i v e r | \ n | 13 | N o | d r i v e r | \ n + - - - - - - - - - - + - - - - - - - - + - - - - - - - - + \ n < s t r o n g > 输 出 : < / s t r o n g > \ n + - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - + \ n | D a y | C a n c e l l a t i o n R a t e | \ n + - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - + \ n | 2013 -10 -0 1 | 0.33 | \ n | 2013 -10 -0 2 | 0.00 | \ n | 2013 -10 -0 3 | 0.50 | \ n + - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - + \ n < s t r o n g > 解 释 : < / s t r o n g > \ n 2013 -10 -0 1 : \ n - 共 有 4 条 请 求 <EFBFBD>
2022-03-27 20:56:26 +08:00
"isPaidOnly" : false ,
"difficulty" : "Hard" ,
2023-12-09 18:42:21 +08:00
"likes" : 422 ,
2022-03-27 20:56:26 +08:00
"dislikes" : 0 ,
"isLiked" : null ,
"similarQuestions" : "[]" ,
"contributors" : [ ] ,
2023-12-09 18:42:21 +08:00
"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}" ,
2022-03-27 20:56:26 +08:00
"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"
2023-12-09 18:42:21 +08:00
} ,
{
"lang" : "Pandas" ,
"langSlug" : "pythondata" ,
"code" : "import pandas as pd\n\ndef trips_and_users(trips: pd.DataFrame, users: pd.DataFrame) -> pd.DataFrame:\n " ,
"__typename" : "CodeSnippetNode"
} ,
{
"lang" : "PostgreSQL" ,
"langSlug" : "postgresql" ,
"code" : "-- Write your PostgreSQL query statement below" ,
"__typename" : "CodeSnippetNode"
2022-03-27 20:56:26 +08:00
}
] ,
2023-12-09 19:57:46 +08:00
"stats" : "{\"totalAccepted\": \"73K\", \"totalSubmission\": \"178.2K\", \"totalAcceptedRaw\": 73014, \"totalSubmissionRaw\": 178243, \"acRate\": \"41.0%\"}" ,
2022-03-27 20:56:26 +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\"]]}}" ,
2023-12-09 18:42:21 +08:00
"metaData" : "{\"mysql\":[\"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'))\"],\"mssql\":[\"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))\",\"Create table Users (users_id int, banned varchar(50), role VARCHAR(10) NOT NULL CHECK (role IN ('client', 'driver', 'partner')))\"],\"oraclesql\":[\"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))\",\"Create table Users (users_id int, banned varchar(50), role VARCHAR(10) NOT NULL CHECK (role IN ('client', 'driver', 'partner')))\"],\"database\":true,\"name\":\"trips_and_users\",\"pythondata\":[\"Trips = pd.DataFrame([], columns=['id', 'client_id', 'driver_id', 'city_id', 'status', 'request_at']).astype({'id':'Int64', 'client_id':'Int64', 'driver_id':'Int64', 'city_id':'Int64', 'status':'object', 'request_at':'object'})\\n\",\"Users = pd.DataFrame([], columns=['users_id', 'banned', 'role']).astype({'users_id':'Int64', 'banned':'object', 'role':'object'})\"],\"postgresql\":[\"Create table If Not Exists Trips (id int, client_id int, driver_id int, city_id int, status VARCHAR(30) CHECK (status IN ('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 VARCHAR(30) CHECK (role IN ('client', 'driver', 'partner')))\\n\"],\"database_schema\":{\"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)\"},\"Users\":{\"users_id\":\"INT\",\"banned\":\"VARCHAR(50)\",\"role\":\"ENUM('client', 'driver', 'partner')\"}}}" ,
2022-03-27 20:56:26 +08:00
"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 ,
2023-12-09 18:42:21 +08:00
"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>\"]}" ,
2022-03-27 20:56:26 +08:00
"book" : null ,
"isSubscribed" : false ,
"isDailyQuestion" : false ,
"dailyRecordStatus" : null ,
"editorType" : "CKEDITOR" ,
"ugcQuestionId" : null ,
"style" : "LEETCODE" ,
"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\"]]}}" ,
"__typename" : "QuestionNode"
}
}
}