|
1 |
| ---1173. Immediate Food Delivery I |
2 |
| --- |
3 |
| ---Table: Delivery |
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 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 |
| ---If the preferred delivery date of the customer is the same as the order date then the order is called immediate otherwise it's called scheduled. |
15 |
| --- |
16 |
| ---Write an SQL query to find the percentage of immediate orders in the table, rounded to 2 decimal places. |
17 |
| ---The query result format is in the following example: |
18 |
| ---Delivery table: |
19 |
| ---+-------------+-------------+------------+-----------------------------+ |
20 |
| ---| delivery_id | customer_id | order_date | customer_pref_delivery_date | |
21 |
| ---+-------------+-------------+------------+-----------------------------+ |
22 |
| ---| 1 | 1 | 2019-08-01 | 2019-08-02 | |
23 |
| ---| 2 | 5 | 2019-08-02 | 2019-08-02 | |
24 |
| ---| 3 | 1 | 2019-08-11 | 2019-08-11 | |
25 |
| ---| 4 | 3 | 2019-08-24 | 2019-08-26 | |
26 |
| ---| 5 | 4 | 2019-08-21 | 2019-08-22 | |
27 |
| ---| 6 | 2 | 2019-08-11 | 2019-08-13 | |
28 |
| ---+-------------+-------------+------------+-----------------------------+ |
29 |
| --- |
30 |
| ---Result table: |
31 |
| ---+----------------------+ |
32 |
| ---| immediate_percentage | |
33 |
| ---+----------------------+ |
34 |
| ---| 33.33 | |
35 |
| ---+----------------------+ |
36 |
| ---The orders with delivery id 2 and 3 are immediate while the others are scheduled. |
37 |
| - |
38 |
| - |
39 |
| -# Write your MySQL query statement below |
40 | 1 | select round(
|
41 | 2 | (
|
42 | 3 | 100 * (select count(*) from Delivery d where d.order_date = d.customer_pref_delivery_date)/
|
|
0 commit comments