Skip to content

Commit b9cba6c

Browse files
committed
feat: add new lc problems
1 parent fbfc994 commit b9cba6c

File tree

8 files changed

+513
-3
lines changed

8 files changed

+513
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# [2686. Immediate Food Delivery III](https://leetcode.cn/problems/immediate-food-delivery-iii)
2+
3+
[English Version](/solution/2600-2699/2686.Immediate%20Food%20Delivery%20III/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>Table: <code>Delivery</code></p>
10+
11+
<pre>
12+
+-----------------------------+---------+
13+
| Column Name | Type |
14+
+-----------------------------+---------+
15+
| delivery_id | int |
16+
| customer_id | int |
17+
| order_date | date |
18+
| customer_pref_delivery_date | date |
19+
+-----------------------------+---------+
20+
delivery_id is the primary key of this table.
21+
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).
22+
</pre>
23+
24+
<p>If the customer&#39;s preferred delivery date is the same as the order date, then the order is called <strong>immediate,</strong>&nbsp;otherwise, it is <strong>scheduled</strong>.</p>
25+
26+
<p>Write an SQL query to find the percentage of immediate orders on each unique&nbsp;<code>order_date</code>, <strong>rounded to 2 decimal places</strong>.&nbsp;</p>
27+
28+
<p>Return <em>the result table ordered by</em> <code>order_date</code> <em>in <strong>ascending</strong> order.</em></p>
29+
30+
<p>The query result format is in the following example.</p>
31+
32+
<p>&nbsp;</p>
33+
<p><strong class="example">Example 1:</strong></p>
34+
35+
<pre>
36+
<strong>Input:</strong>
37+
Delivery table:
38+
+-------------+-------------+------------+-----------------------------+
39+
| delivery_id | customer_id | order_date | customer_pref_delivery_date |
40+
+-------------+-------------+------------+-----------------------------+
41+
| 1 | 1 | 2019-08-01 | 2019-08-02 |
42+
| 2 | 2 | 2019-08-01 | 2019-08-01 |
43+
| 3 | 1 | 2019-08-01 | 2019-08-01 |
44+
| 4 | 3 | 2019-08-02 | 2019-08-13 |
45+
| 5 | 3 | 2019-08-02 | 2019-08-02 |
46+
| 6 | 2 | 2019-08-02 | 2019-08-02 |
47+
| 7 | 4 | 2019-08-03 | 2019-08-03 |
48+
| 8 | 1 | 2019-08-03 | 2019-08-03 |
49+
| 9 | 5 | 2019-08-04 | 2019-08-08 |
50+
| 10 | 2 | 2019-08-04 | 2019-08-18 |
51+
+-------------+-------------+------------+-----------------------------+
52+
<strong>Output:</strong>
53+
+------------+----------------------+
54+
| order_date | immediate_percentage |
55+
+------------+----------------------+
56+
| 2019-08-01 | 66.67 |
57+
| 2019-08-02 | 66.67 |
58+
| 2019-08-03 | 100.00 |
59+
| 2019-08-04 | 0.00 |
60+
+------------+----------------------+
61+
<strong>Explanation:</strong>
62+
- 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.
63+
- 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.
64+
- On 2019-08-03 there were two orders, both were immediate. So, the immediate percentage for that date was 100.00.
65+
- On 2019-08-04 there were two orders, both were scheduled. So, the immediate percentage for that date was 0.00.
66+
order_date is sorted in ascending order.
67+
</pre>
68+
69+
70+
## 解法
71+
72+
<!-- 这里可写通用的实现逻辑 -->
73+
74+
<!-- tabs:start -->
75+
76+
### **SQL**
77+
78+
<!-- 这里可写当前语言的特殊实现逻辑 -->
79+
80+
```sql
81+
82+
```
83+
84+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# [2686. Immediate Food Delivery III](https://leetcode.com/problems/immediate-food-delivery-iii)
2+
3+
[中文文档](/solution/2600-2699/2686.Immediate%20Food%20Delivery%20III/README.md)
4+
5+
## Description
6+
7+
<p>Table: <code>Delivery</code></p>
8+
9+
<pre>
10+
+-----------------------------+---------+
11+
| Column Name | Type |
12+
+-----------------------------+---------+
13+
| delivery_id | int |
14+
| customer_id | int |
15+
| order_date | date |
16+
| customer_pref_delivery_date | date |
17+
+-----------------------------+---------+
18+
delivery_id is the primary key of this table.
19+
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).
20+
</pre>
21+
22+
<p>If the customer&#39;s preferred delivery date is the same as the order date, then the order is called <strong>immediate,</strong>&nbsp;otherwise, it is <strong>scheduled</strong>.</p>
23+
24+
<p>Write an SQL query to find the percentage of immediate orders on each unique&nbsp;<code>order_date</code>, <strong>rounded to 2 decimal places</strong>.&nbsp;</p>
25+
26+
<p>Return <em>the result table ordered by</em> <code>order_date</code> <em>in <strong>ascending</strong> order.</em></p>
27+
28+
<p>The query result format is in the following example.</p>
29+
30+
<p>&nbsp;</p>
31+
<p><strong class="example">Example 1:</strong></p>
32+
33+
<pre>
34+
<strong>Input:</strong>
35+
Delivery table:
36+
+-------------+-------------+------------+-----------------------------+
37+
| delivery_id | customer_id | order_date | customer_pref_delivery_date |
38+
+-------------+-------------+------------+-----------------------------+
39+
| 1 | 1 | 2019-08-01 | 2019-08-02 |
40+
| 2 | 2 | 2019-08-01 | 2019-08-01 |
41+
| 3 | 1 | 2019-08-01 | 2019-08-01 |
42+
| 4 | 3 | 2019-08-02 | 2019-08-13 |
43+
| 5 | 3 | 2019-08-02 | 2019-08-02 |
44+
| 6 | 2 | 2019-08-02 | 2019-08-02 |
45+
| 7 | 4 | 2019-08-03 | 2019-08-03 |
46+
| 8 | 1 | 2019-08-03 | 2019-08-03 |
47+
| 9 | 5 | 2019-08-04 | 2019-08-08 |
48+
| 10 | 2 | 2019-08-04 | 2019-08-18 |
49+
+-------------+-------------+------------+-----------------------------+
50+
<strong>Output:</strong>
51+
+------------+----------------------+
52+
| order_date | immediate_percentage |
53+
+------------+----------------------+
54+
| 2019-08-01 | 66.67 |
55+
| 2019-08-02 | 66.67 |
56+
| 2019-08-03 | 100.00 |
57+
| 2019-08-04 | 0.00 |
58+
+------------+----------------------+
59+
<strong>Explanation:</strong>
60+
- 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.
61+
- 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.
62+
- On 2019-08-03 there were two orders, both were immediate. So, the immediate percentage for that date was 100.00.
63+
- On 2019-08-04 there were two orders, both were scheduled. So, the immediate percentage for that date was 0.00.
64+
order_date is sorted in ascending order.
65+
</pre>
66+
67+
68+
## Solutions
69+
70+
<!-- tabs:start -->
71+
72+
### **SQL**
73+
74+
```sql
75+
76+
```
77+
78+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# [2687. Bikes Last Time Used](https://leetcode.cn/problems/bikes-last-time-used)
2+
3+
[English Version](/solution/2600-2699/2687.Bikes%20Last%20Time%20Used/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>Table: <code><font face="monospace">Bikes</font></code></p>
10+
11+
<pre>
12+
+-------------+----------+
13+
| Column Name | Type |
14+
+-------------+----------+
15+
| ride_id | int |
16+
| bike_number | int |
17+
| start_time | datetime |
18+
| end_time | datetime |
19+
+-------------+----------+
20+
ride_id is the primary key for this table.
21+
Each row contains a ride information that includes ride_id, bike number, start and end time of the ride.
22+
</pre>
23+
24+
<p>Write an SQL query to find the <strong>last</strong> <strong>time</strong> when each bike was used.</p>
25+
26+
<p>Return<em> the result table ordered by the bikes that were <strong>most recently used</strong>.&nbsp;</em></p>
27+
28+
<p>The query result format is in the following example.</p>
29+
30+
<p>&nbsp;</p>
31+
<p><strong class="example">Example 1:</strong></p>
32+
33+
<pre>
34+
<strong>Input:
35+
</strong><code>Bikes</code> table:
36+
+---------+-------------+---------------------+---------------------+
37+
| ride_id | bike_number | start_time | end_time |
38+
+---------+-------------+---------------------+---------------------+
39+
| 1 | W00576 | 2012-03-25 11:30:00 | 2012-03-25 12:40:00 |
40+
| 2 | W00300 | 2012-03-25 10:30:00 | 2012-03-25 10:50:00 |
41+
| 3 | W00455 | 2012-03-26 14:30:00 | 2012-03-26 17:40:00 |
42+
| 4 | W00455 | 2012-03-25 12:30:00 | 2012-03-25 13:40:00 |
43+
| 5 | W00576 | 2012-03-25 08:10:00 | 2012-03-25 09:10:00 |
44+
| 6 | W00576 | 2012-03-28 02:30:00 | 2012-03-28 02:50:00 |
45+
+---------+-------------+---------------------+---------------------+
46+
47+
<strong>Output:</strong>
48+
+-------------+---------------------+
49+
| bike_number | end_time |
50+
+-------------+---------------------+
51+
| W00576 | 2012-03-28 02:50:00 |
52+
| W00455 | 2012-03-26 17:40:00 |
53+
| W00300 | 2012-03-25 10:50:00 |
54+
+-------------+---------------------+
55+
<strong>Explanation:</strong>
56+
bike with number W00576 has three rides, out of that, most recent ride is with ride_id 6 which ended on 2012-03-28 02:50:00.
57+
bike with number W00300 has only 1 ride so we will include end_time in output directly.
58+
bike with number W00455 has two rides, out of that, most recent ride is with ride_id 3 which ended on 2012-03-26 17:40:00.
59+
Returning output in order by the bike that were most recently used.
60+
</pre>
61+
62+
<p>&nbsp;</p>
63+
64+
65+
## 解法
66+
67+
<!-- 这里可写通用的实现逻辑 -->
68+
69+
<!-- tabs:start -->
70+
71+
### **SQL**
72+
73+
<!-- 这里可写当前语言的特殊实现逻辑 -->
74+
75+
```sql
76+
77+
```
78+
79+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# [2687. Bikes Last Time Used](https://leetcode.com/problems/bikes-last-time-used)
2+
3+
[中文文档](/solution/2600-2699/2687.Bikes%20Last%20Time%20Used/README.md)
4+
5+
## Description
6+
7+
<p>Table: <code><font face="monospace">Bikes</font></code></p>
8+
9+
<pre>
10+
+-------------+----------+
11+
| Column Name | Type |
12+
+-------------+----------+
13+
| ride_id | int |
14+
| bike_number | int |
15+
| start_time | datetime |
16+
| end_time | datetime |
17+
+-------------+----------+
18+
ride_id is the primary key for this table.
19+
Each row contains a ride information that includes ride_id, bike number, start and end time of the ride.
20+
</pre>
21+
22+
<p>Write an SQL query to find the <strong>last</strong> <strong>time</strong> when each bike was used.</p>
23+
24+
<p>Return<em> the result table ordered by the bikes that were <strong>most recently used</strong>.&nbsp;</em></p>
25+
26+
<p>The query result format is in the following example.</p>
27+
28+
<p>&nbsp;</p>
29+
<p><strong class="example">Example 1:</strong></p>
30+
31+
<pre>
32+
<strong>Input:
33+
</strong><code>Bikes</code> table:
34+
+---------+-------------+---------------------+---------------------+
35+
| ride_id | bike_number | start_time | end_time |
36+
+---------+-------------+---------------------+---------------------+
37+
| 1 | W00576 | 2012-03-25 11:30:00 | 2012-03-25 12:40:00 |
38+
| 2 | W00300 | 2012-03-25 10:30:00 | 2012-03-25 10:50:00 |
39+
| 3 | W00455 | 2012-03-26 14:30:00 | 2012-03-26 17:40:00 |
40+
| 4 | W00455 | 2012-03-25 12:30:00 | 2012-03-25 13:40:00 |
41+
| 5 | W00576 | 2012-03-25 08:10:00 | 2012-03-25 09:10:00 |
42+
| 6 | W00576 | 2012-03-28 02:30:00 | 2012-03-28 02:50:00 |
43+
+---------+-------------+---------------------+---------------------+
44+
45+
<strong>Output:</strong>
46+
+-------------+---------------------+
47+
| bike_number | end_time |
48+
+-------------+---------------------+
49+
| W00576 | 2012-03-28 02:50:00 |
50+
| W00455 | 2012-03-26 17:40:00 |
51+
| W00300 | 2012-03-25 10:50:00 |
52+
+-------------+---------------------+
53+
<strong>Explanation:</strong>
54+
bike with number W00576 has three rides, out of that, most recent ride is with ride_id 6 which ended on 2012-03-28 02:50:00.
55+
bike with number W00300 has only 1 ride so we will include end_time in output directly.
56+
bike with number W00455 has two rides, out of that, most recent ride is with ride_id 3 which ended on 2012-03-26 17:40:00.
57+
Returning output in order by the bike that were most recently used.
58+
</pre>
59+
60+
<p>&nbsp;</p>
61+
62+
63+
## Solutions
64+
65+
<!-- tabs:start -->
66+
67+
### **SQL**
68+
69+
```sql
70+
71+
```
72+
73+
<!-- tabs:end -->

0 commit comments

Comments
 (0)