|
| 1 | +<p>Table: <code>Delivery</code></p> |
| 2 | + |
| 3 | +<pre> |
| 4 | ++-----------------------------+---------+ |
| 5 | +| Column Name | Type | |
| 6 | ++-----------------------------+---------+ |
| 7 | +| delivery_id | int | |
| 8 | +| customer_id | int | |
| 9 | +| order_date | date | |
| 10 | +| customer_pref_delivery_date | date | |
| 11 | ++-----------------------------+---------+ |
| 12 | +delivery_id is the primary key (column with unique values) of this table. |
| 13 | +The 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). |
| 14 | +</pre> |
| 15 | + |
| 16 | +<p> </p> |
| 17 | + |
| 18 | +<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> |
| 19 | + |
| 20 | +<p>Write a solution to find the percentage of immediate orders in the table, <strong>rounded to 2 decimal places</strong>.</p> |
| 21 | + |
| 22 | +<p>The result format is in the following example.</p> |
| 23 | + |
| 24 | +<p> </p> |
| 25 | +<p><strong class="example">Example 1:</strong></p> |
| 26 | + |
| 27 | +<pre> |
| 28 | +<strong>Input:</strong> |
| 29 | +Delivery table: |
| 30 | ++-------------+-------------+------------+-----------------------------+ |
| 31 | +| delivery_id | customer_id | order_date | customer_pref_delivery_date | |
| 32 | ++-------------+-------------+------------+-----------------------------+ |
| 33 | +| 1 | 1 | 2019-08-01 | 2019-08-02 | |
| 34 | +| 2 | 5 | 2019-08-02 | 2019-08-02 | |
| 35 | +| 3 | 1 | 2019-08-11 | 2019-08-11 | |
| 36 | +| 4 | 3 | 2019-08-24 | 2019-08-26 | |
| 37 | +| 5 | 4 | 2019-08-21 | 2019-08-22 | |
| 38 | +| 6 | 2 | 2019-08-11 | 2019-08-13 | |
| 39 | ++-------------+-------------+------------+-----------------------------+ |
| 40 | +<strong>Output:</strong> |
| 41 | ++----------------------+ |
| 42 | +| immediate_percentage | |
| 43 | ++----------------------+ |
| 44 | +| 33.33 | |
| 45 | ++----------------------+ |
| 46 | +<strong>Explanation:</strong> The orders with delivery id 2 and 3 are immediate while the others are scheduled. |
| 47 | +</pre> |
0 commit comments