返回介绍

solution / 2600-2699 / 2686.Immediate Food Delivery III / README_EN

发布于 2024-06-17 01:03:01 字数 3689 浏览 0 评论 0 收藏 0

2686. Immediate Food Delivery III

中文文档

Description

Table: Delivery

+-----------------------------+---------+
| Column Name         | Type  |
+-----------------------------+---------+
| delivery_id         | int   |
| customer_id         | int   |
| order_date          | date  |
| customer_pref_delivery_date | date  |
+-----------------------------+---------+
delivery_id is the column with unique values of this table.
Each row contains information about food delivery to a customer that makes an order at some date and specifies a preferred delivery date (on the order date or after it).

If the customer's preferred delivery date is the same as the order date, then the order is called immediate, otherwise, it is scheduled.

Write a solution to find the percentage of immediate orders on each unique order_date, rounded to 2 decimal places

Return _the result table ordered by_ order_date _in ascending order._

The result format is in the following example.

 

Example 1:

Input: 
Delivery table:
+-------------+-------------+------------+-----------------------------+
| delivery_id | customer_id | order_date | customer_pref_delivery_date |
+-------------+-------------+------------+-----------------------------+
| 1       | 1       | 2019-08-01 | 2019-08-02          |
| 2       | 2       | 2019-08-01 | 2019-08-01          |
| 3       | 1       | 2019-08-01 | 2019-08-01          |
| 4       | 3       | 2019-08-02 | 2019-08-13          |
| 5       | 3       | 2019-08-02 | 2019-08-02          |
| 6       | 2       | 2019-08-02 | 2019-08-02          |
| 7       | 4       | 2019-08-03 | 2019-08-03          |
| 8       | 1       | 2019-08-03 | 2019-08-03          |
| 9       | 5       | 2019-08-04 | 2019-08-08          |
| 10      | 2       | 2019-08-04 | 2019-08-18          |
+-------------+-------------+------------+-----------------------------+
Output: 
+------------+----------------------+
| order_date | immediate_percentage |
+------------+----------------------+
| 2019-08-01 | 66.67        |
| 2019-08-02 | 66.67        |
| 2019-08-03 | 100.00         |
| 2019-08-04 | 0.00         |
+------------+----------------------+
Explanation: 
- On 2019-08-01 there were three orders, out of those, two were immediate and one was scheduled. So, immediate percentage for that date was 66.67.
- On 2019-08-02 there were three orders, out of those, two were immediate and one was scheduled. So, immediate percentage for that date was 66.67.
- On 2019-08-03 there were two orders, both were immediate. So, the immediate percentage for that date was 100.00.
- On 2019-08-04 there were two orders, both were scheduled. So, the immediate percentage for that date was 0.00.
order_date is sorted in ascending order.

Solutions

Solution 1

# Write your MySQL query statement below
SELECT  order_date
     ,ROUND(100*SUM(IF(customer_pref_delivery_date = order_date,1,0))/COUNT(*),2) AS immediate_percentage
FROM Delivery
GROUP BY  order_date
ORDER BY order_date

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文