2023-12-09 18:53:53 +08:00
{
"data" : {
"question" : {
"questionId" : "1292" ,
"questionFrontendId" : "1174" ,
"categoryTitle" : "Database" ,
"boundTopicId" : 33159 ,
"title" : "Immediate Food Delivery II" ,
"titleSlug" : "immediate-food-delivery-ii" ,
"content" : "<p>Table: <code>Delivery</code></p>\n\n<pre>\n+-----------------------------+---------+\n| Column Name | Type |\n+-----------------------------+---------+\n| delivery_id | int |\n| customer_id | int |\n| order_date | date |\n| customer_pref_delivery_date | date |\n+-----------------------------+---------+\ndelivery_id is the column of unique values of this table.\nThe table holds information about food delivery to customers that make orders at some date and specify a preferred delivery date (on the same order date or after it).\n</pre>\n\n<p> </p>\n\n<p>If the customer's preferred delivery date is the same as the order date, then the order is called <strong>immediate;</strong> otherwise, it is called <strong>scheduled</strong>.</p>\n\n<p>The <strong>first order</strong> of a customer is the order with the earliest order date that the customer made. It is guaranteed that a customer has precisely one first order.</p>\n\n<p>Write a solution to find the percentage of immediate orders in the first orders of all customers, <strong>rounded to 2 decimal places</strong>.</p>\n\n<p>The result format is in the following example.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \nDelivery table:\n+-------------+-------------+------------+-----------------------------+\n| delivery_id | customer_id | order_date | customer_pref_delivery_date |\n+-------------+-------------+------------+-----------------------------+\n| 1 | 1 | 2019-08-01 | 2019-08-02 |\n| 2 | 2 | 2019-08-02 | 2019-08-02 |\n| 3 | 1 | 2019-08-11 | 2019-08-12 |\n| 4 | 3 | 2019-08-24 | 2019-08-24 |\n| 5 | 3 | 2019-08-21 | 2019-08-22 |\n| 6 | 2 | 2019-08-11 | 2019-08-13 |\n| 7 | 4 | 2019-08-09 | 2019-08-09 |\n+-------------+-------------+------------+-----------------------------+\n<strong>Output:</strong> \n+----------------------+\n| immediate_percentage |\n+----------------------+\n| 50.00 |\n+----------------------+\n<strong>Explanation:</strong> \nThe customer id 1 has a first order with delivery id 1 and it is scheduled.\nThe customer id 2 has a first order with delivery id 2 and it is immediate.\nThe customer id 3 has a first order with delivery id 5 and it is scheduled.\nThe customer id 4 has a first order with delivery id 7 and it is immediate.\nHence, half the customers have immediate first orders.\n</pre>\n" ,
"translatedTitle" : "即时食物配送 II" ,
"translatedContent" : "<p>配送表: <code>Delivery</code></p>\n\n<pre>\n+-----------------------------+---------+\n| Column Name | Type |\n+-----------------------------+---------+\n| delivery_id | int |\n| customer_id | int |\n| order_date | date |\n| customer_pref_delivery_date | date |\n+-----------------------------+---------+\ndelivery_id 是该表中具有唯一值的列。\n该表保存着顾客的食物配送信息, 顾客在某个日期下了订单, 并指定了一个期望的配送日期( 和下单日期相同或者在那之后) 。\n</pre>\n\n<p> </p>\n\n<p>如果顾客期望的配送日期和下单日期相同,则该订单称为 「<strong>即时订单</strong>」,否则称为「<strong>计划订单</strong>」。</p>\n\n<p>「<strong>首次订单</strong>」是顾客最早创建的订单。我们保证一个顾客只会有一个「首次订单」。</p>\n\n<p>编写解决方案以获取即时订单在所有用户的首次订单中的比例。<strong>保留两位小数。</strong></p>\n\n<p>结果示例如下所示:</p>\n\n<p> </p>\n\n<p><strong>示例 1: </strong></p>\n\n<pre>\n<strong>输入:</strong>\nDelivery 表:\n+-------------+-------------+------------+-----------------------------+\n| delivery_id | customer_id | order_date | customer_pref_delivery_date |\n+-------------+-------------+------------+-----------------------------+\n| 1 | 1 | 2019-08-01 | 2019-08-02 |\n| 2 | 2 | 2019-08-02 | 2019-08-02 |\n| 3 | 1 | 2019-08-11 | 2019-08-12 |\n| 4 | 3 | 2019-08-24 | 2019-08-24 |\n| 5 | 3 | 2019-08-21 | 2019-08-22 |\n| 6 | 2 | 2019-08-11 | 2019-08-13 |\n| 7 | 4 | 2019-08-09 | 2019-08-09 |\n+-------------+-------------+------------+-----------------------------+\n<strong>输出:</strong>\n+----------------------+\n| immediate_percentage |\n+----------------------+\n| 50.00 |\n+----------------------+\n<strong>解释:</strong>\n1 号顾客的 1 号订单是首次订单,并且是计划订单。\n2 号顾客的 2 号订单是首次订单,并且是即时订单。\n3 号顾客的 5 号订单是首次订单,并且是计划订单。\n4 号顾客的 7 号订单是首次订单,并且是即时订单。\n因此, 一半顾客的首次订单是即时的。\n</pre>\n" ,
"isPaidOnly" : false ,
"difficulty" : "Medium" ,
"likes" : 77 ,
"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 immediate_food_delivery(delivery: pd.DataFrame) -> pd.DataFrame:\n " ,
"__typename" : "CodeSnippetNode"
} ,
{
"lang" : "PostgreSQL" ,
"langSlug" : "postgresql" ,
"code" : "-- Write your PostgreSQL query statement below" ,
"__typename" : "CodeSnippetNode"
}
] ,
2023-12-09 19:57:46 +08:00
"stats" : "{\"totalAccepted\": \"22K\", \"totalSubmission\": \"39.6K\", \"totalAcceptedRaw\": 21991, \"totalSubmissionRaw\": 39586, \"acRate\": \"55.6%\"}" ,
2023-12-09 18:53:53 +08:00
"hints" : [ ] ,
"solution" : null ,
"status" : null ,
"sampleTestCase" : "{\"headers\":{\"Delivery\":[\"delivery_id\",\"customer_id\",\"order_date\",\"customer_pref_delivery_date\"]},\"rows\":{\"Delivery\":[[1,1,\"2019-08-01\",\"2019-08-02\"],[2,2,\"2019-08-02\",\"2019-08-02\"],[3,1,\"2019-08-11\",\"2019-08-12\"],[4,3,\"2019-08-24\",\"2019-08-24\"],[5,3,\"2019-08-21\",\"2019-08-22\"],[6,2,\"2019-08-11\",\"2019-08-13\"],[7,4,\"2019-08-09\",\"2019-08-09\"]]}}" ,
"metaData" : "{\"mysql\":[\"Create table If Not Exists Delivery (delivery_id int, customer_id int, order_date date, customer_pref_delivery_date date)\"],\"mssql\":[\"Create table Delivery (delivery_id int, customer_id int, order_date date, customer_pref_delivery_date date)\"],\"oraclesql\":[\"Create table Delivery (delivery_id int, customer_id int, order_date date, customer_pref_delivery_date date)\",\"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"],\"database\":true,\"name\":\"immediate_food_delivery\",\"pythondata\":[\"Delivery = pd.DataFrame([], columns=['delivery_id', 'customer_id', 'order_date', 'customer_pref_delivery_date']).astype({'delivery_id':'Int64', 'customer_id':'Int64', 'order_date':'datetime64[ns]', 'customer_pref_delivery_date':'datetime64[ns]'})\"],\"postgresql\":[\"\\nCreate table If Not Exists Delivery (delivery_id int, customer_id int, order_date date, customer_pref_delivery_date date)\"],\"database_schema\":{\"Delivery\":{\"delivery_id\":\"INT\",\"customer_id\":\"INT\",\"order_date\":\"DATE\",\"customer_pref_delivery_date\":\"DATE\"}}}" ,
"judgerAvailable" : true ,
"judgeType" : "large" ,
"mysqlSchemas" : [
"Create table If Not Exists Delivery (delivery_id int, customer_id int, order_date date, customer_pref_delivery_date date)" ,
"Truncate table Delivery" ,
"insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('1', '1', '2019-08-01', '2019-08-02')" ,
"insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('2', '2', '2019-08-02', '2019-08-02')" ,
"insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('3', '1', '2019-08-11', '2019-08-12')" ,
"insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('4', '3', '2019-08-24', '2019-08-24')" ,
"insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('5', '3', '2019-08-21', '2019-08-22')" ,
"insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('6', '2', '2019-08-11', '2019-08-13')" ,
"insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('7', '4', '2019-08-09', '2019-08-09')"
] ,
"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\":{\"Delivery\":[\"delivery_id\",\"customer_id\",\"order_date\",\"customer_pref_delivery_date\"]},\"rows\":{\"Delivery\":[[1,1,\"2019-08-01\",\"2019-08-02\"],[2,2,\"2019-08-02\",\"2019-08-02\"],[3,1,\"2019-08-11\",\"2019-08-12\"],[4,3,\"2019-08-24\",\"2019-08-24\"],[5,3,\"2019-08-21\",\"2019-08-22\"],[6,2,\"2019-08-11\",\"2019-08-13\"],[7,4,\"2019-08-09\",\"2019-08-09\"]]}}" ,
"__typename" : "QuestionNode"
}
}
}