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 > T a b l e : < c o d e > T r i p s < / c o d e > < / p > \ n \ n < p r e > \ n + - - - - - - - - - - - - - + - - - - - - - - - - + \ n | C o l u m n N a m e | T y p e | \ n + - - - - - - - - - - - - - + - - - - - - - - - - + \ n | i d | i n t | \ n | c l i e n t _ i d | i n t | \ n | d r i v e r _ i d | i n t | \ n | c i t y _ i d | i n t | \ n | s t a t u s | e n u m | \ n | r e q u e s t _ a t | d a t e | \ n + - - - - - - - - - - - - - + - - - - - - - - - - + \ n i d i s t h e p r i m a r y k e y f o r t h i s t a b l e . \ n T h e t a b l e h o l d s a l l t a x i t r i p s . E a c h t r i p h a s a u n i q u e i d , w h i l e c l i e n t _ i d a n d d r i v e r _ i d a r e f o r e i g n k e y s t o t h e u s e r s _ i d a t t h e U s e r s t a b l e . \ n S t a t u s i s a n E N U M t y p e o f ( & # 39 ; c o m p l e t e d & # 39 ; , & # 39 ; c a n c e l l e d _ b y _ d r i v e r & # 39 ; , & # 39 ; c a n c e l l e d _ b y _ c l i e n t & # 39 ; ) . \ n < / p r e > \ n \ n < p > & n b s p ; < / p > \ n \ n < p > T a b l e : < c o d e > U s e r s < / c o d e > < / p > \ n \ n < p r e > \ n + - - - - - - - - - - - - - + - - - - - - - - - - + \ n | C o l u m n N a m e | T y p e | \ n + - - - - - - - - - - - - - + - - - - - - - - - - + \ n | u s e r s _ i d | i n t | \ n | b a n n e d | e n u m | \ n | r o l e | e n u m | \ n + - - - - - - - - - - - - - + - - - - - - - - - - + \ n u s e r s _ i d i s t h e p r i m a r y k e y f o r t h i s t a b l e . \ n T h e t a b l e h o l d s a l l u s e r s . E a c h u s e r h a s a u n i q u e u s e r s _ i d , a n d r o l e i s a n E N U M t y p e o f ( & # 39 ; c l i e n t & # 39 ; , & # 39 ; d r i v e r & # 39 ; , & # 39 ; p a r t n e r & # 39 ; ) . \ n b a n n e d i s a n E N U M t y p e o f ( & # 39 ; Y e s & # 39 ; , & # 39 ; N o & # 39 ; ) . \ n < / p r e > \ n \ n < p > & n b s p ; < / p > \ n \ n < p > T h e < s t r o n g > c a n c e l l a t i o n r a t e < / s t r o n g > i s c o m p u t e d b y d i v i d i n g t h e n u m b e r o f c a n c e l e d ( b y c l i e n t o r d r i v e r ) r e q u e s t s w i t h u n b a n n e d u s e r s b y t h e t o t a l n u m b e r o f r e q u e s t s w i t h u n b a n n e d u s e r s o n t h a t d a y . < / p > \ n \ n < p > W r i t e a S Q L q u e r y t o f i n d t h e < s t r o n g > c a n c e l l a t i o n r a t e < / s t r o n g > o f r e q u e s t s w i t h u n b a n n e d u s e r s ( < s t r o n g > b o t h c l i e n t a n d d r i v e r m u s t n o t b e b a n n e d < / s t r o n g > ) e a c h d a y b e t w e e n < c o d e > & q u o t ; 2013 -10 -0 1 & q u o t ; < / c o d e > a n d < c o d e > & q u o t ; 2013 -10 -0 3 & q u o t ; < / c o d e > . R o u n d < c o d e > C a n c e l l a t i o n R a t e < / c o d e > t o < s t r o n g > t w o d e c i m a l < / s t r o n g > p o i n t s . < / p > \ n \ n < p > R e t u r n t h e r e s u l t t a b l e i n < s t r o n g > a n y o r d e r < / s t r o n g > . < / p > \ n \ n < p > T h e q u e r y r e s u l t f o r m a t i s i n t h e f o l l o w i n g e x a m p l e . < / p > \ n \ n < p > & n b s p ; < / p > \ n < p > < s t r o n g > 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 w h i c h w a s c a n c e l e d . \ n - T h e C a n c e l l a t i o n R a t e i s ( 1 / 3 ) = 0.33 \ n O n 2013 -10 -0 2 : \ n - T h e r e 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"
}
}
}