Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ab7bf42

Browse files
authored
feat: add new lc problems (doocs#2181)
1 parent 7c6b9bb commit ab7bf42

File tree

14 files changed

+471
-2
lines changed

14 files changed

+471
-2
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# [2993. Friday Purchases I](https://leetcode.cn/problems/friday-purchases-i)
2+
3+
[English Version](/solution/2900-2999/2993.Friday%20Purchases%20I/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>Table: <code>Purchases</code></p>
10+
11+
<pre>
12+
+---------------+------+
13+
| Column Name | Type |
14+
+---------------+------+
15+
| user_id | int |
16+
| purchase_date | date |
17+
| amount_spend | int |
18+
+---------------+------+
19+
(user_id, purchase_date, amount_spend) is the primary key (combination of columns with unique values) for this table.
20+
purchase_date will range from November 1, 2023, to November 30, 2023, inclusive of both dates.
21+
Each row contains user id, purchase date, and amount spend.
22+
</pre>
23+
24+
<p>Write a solution to calculate the <strong>total spending</strong> by users on <strong>each Friday</strong> of <strong>every week</strong> in <strong>November 2023</strong>. Output only weeks that include <strong>at least one</strong> purchase on a <strong>Friday</strong>.</p>
25+
26+
<p>Return <em>the result table ordered by week of month</em><em> in <strong>ascending</strong></em><em><strong> </strong>order.</em></p>
27+
28+
<p>The 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+
Purchases table:
36+
+---------+---------------+--------------+
37+
| user_id | purchase_date | amount_spend |
38+
+---------+---------------+--------------+
39+
| 11 | 2023年11月07日 | 1126 |
40+
| 15 | 2023年11月30日 | 7473 |
41+
| 17 | 2023年11月14日 | 2414 |
42+
| 12 | 2023年11月24日 | 9692 |
43+
| 8 | 2023年11月03日 | 5117 |
44+
| 1 | 2023年11月16日 | 5241 |
45+
| 10 | 2023年11月12日 | 8266 |
46+
| 13 | 2023年11月24日 | 12000 |
47+
+---------+---------------+--------------+
48+
<strong>Output:</strong>
49+
+---------------+---------------+--------------+
50+
| week_of_month | purchase_date | total_amount |
51+
+---------------+---------------+--------------+
52+
| 1 | 2023年11月03日 | 5117 |
53+
| 4 | 2023年11月24日 | 21692 |
54+
+---------------+---------------+--------------+
55+
<strong>Explanation:</strong>
56+
- During the first week of November 2023, transactions amounting to 5,117ドル occurred on Friday, 2023年11月03日.
57+
- For the second week of November 2023, there were no transactions on Friday, 2023年11月10日.
58+
- Similarly, during the third week of November 2023, there were no transactions on Friday, 2023年11月17日.
59+
- In the fourth week of November 2023, two transactions took place on Friday, 2023年11月24日, amounting to 12,000ドル and 9,692ドル respectively, summing up to a total of 21,692ドル.
60+
Output table is ordered by week_of_month in ascending order.</pre>
61+
62+
## 解法
63+
64+
<!-- 这里可写通用的实现逻辑 -->
65+
66+
<!-- tabs:start -->
67+
68+
### **SQL**
69+
70+
<!-- 这里可写当前语言的特殊实现逻辑 -->
71+
72+
```sql
73+
74+
```
75+
76+
<!-- tabs:end -->
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# [2993. Friday Purchases I](https://leetcode.com/problems/friday-purchases-i)
2+
3+
[中文文档](/solution/2900-2999/2993.Friday%20Purchases%20I/README.md)
4+
5+
## Description
6+
7+
<p>Table: <code>Purchases</code></p>
8+
9+
<pre>
10+
+---------------+------+
11+
| Column Name | Type |
12+
+---------------+------+
13+
| user_id | int |
14+
| purchase_date | date |
15+
| amount_spend | int |
16+
+---------------+------+
17+
(user_id, purchase_date, amount_spend) is the primary key (combination of columns with unique values) for this table.
18+
purchase_date will range from November 1, 2023, to November 30, 2023, inclusive of both dates.
19+
Each row contains user id, purchase date, and amount spend.
20+
</pre>
21+
22+
<p>Write a solution to calculate the <strong>total spending</strong> by users on <strong>each Friday</strong> of <strong>every week</strong> in <strong>November 2023</strong>. Output only weeks that include <strong>at least one</strong> purchase on a <strong>Friday</strong>.</p>
23+
24+
<p>Return <em>the result table ordered by week of month</em><em> in <strong>ascending</strong></em><em><strong> </strong>order.</em></p>
25+
26+
<p>The 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:</strong>
33+
Purchases table:
34+
+---------+---------------+--------------+
35+
| user_id | purchase_date | amount_spend |
36+
+---------+---------------+--------------+
37+
| 11 | 2023年11月07日 | 1126 |
38+
| 15 | 2023年11月30日 | 7473 |
39+
| 17 | 2023年11月14日 | 2414 |
40+
| 12 | 2023年11月24日 | 9692 |
41+
| 8 | 2023年11月03日 | 5117 |
42+
| 1 | 2023年11月16日 | 5241 |
43+
| 10 | 2023年11月12日 | 8266 |
44+
| 13 | 2023年11月24日 | 12000 |
45+
+---------+---------------+--------------+
46+
<strong>Output:</strong>
47+
+---------------+---------------+--------------+
48+
| week_of_month | purchase_date | total_amount |
49+
+---------------+---------------+--------------+
50+
| 1 | 2023年11月03日 | 5117 |
51+
| 4 | 2023年11月24日 | 21692 |
52+
+---------------+---------------+--------------+
53+
<strong>Explanation:</strong>
54+
- During the first week of November 2023, transactions amounting to 5,117ドル occurred on Friday, 2023年11月03日.
55+
- For the second week of November 2023, there were no transactions on Friday, 2023年11月10日.
56+
- Similarly, during the third week of November 2023, there were no transactions on Friday, 2023年11月17日.
57+
- In the fourth week of November 2023, two transactions took place on Friday, 2023年11月24日, amounting to 12,000ドル and 9,692ドル respectively, summing up to a total of 21,692ドル.
58+
Output table is ordered by week_of_month in ascending order.</pre>
59+
60+
## Solutions
61+
62+
<!-- tabs:start -->
63+
64+
### **SQL**
65+
66+
```sql
67+
68+
```
69+
70+
<!-- tabs:end -->
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# [2994. Friday Purchases II](https://leetcode.cn/problems/friday-purchases-ii)
2+
3+
[English Version](/solution/2900-2999/2994.Friday%20Purchases%20II/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>Table: <code>Purchases</code></p>
10+
11+
<pre>
12+
+---------------+------+
13+
| Column Name | Type |
14+
+---------------+------+
15+
| user_id | int |
16+
| purchase_date | date |
17+
| amount_spend | int |
18+
+---------------+------+
19+
(user_id, purchase_date, amount_spend) is the primary key (combination of columns with unique values) for this table.
20+
purchase_date will range from November 1, 2023, to November 30, 2023, inclusive of both dates.
21+
Each row contains user id, purchase date, and amount spend.
22+
</pre>
23+
24+
<p>Write a solution to calculate the <strong>total spending</strong> by users on <strong>each Friday</strong> of <strong>every week</strong> in <strong>November 2023</strong>. If there are <strong>no</strong> purchases on a particular <strong>Friday of a week</strong>, it will be considered as <code>0</code>.</p>
25+
26+
<p>Return <em>the result table ordered by week of month</em><em> in <strong>ascending</strong></em><em><strong> </strong>order.</em></p>
27+
28+
<p>The 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+
Purchases table:
36+
+---------+---------------+--------------+
37+
| user_id | purchase_date | amount_spend |
38+
+---------+---------------+--------------+
39+
| 11 | 2023年11月07日 | 1126 |
40+
| 15 | 2023年11月30日 | 7473 |
41+
| 17 | 2023年11月14日 | 2414 |
42+
| 12 | 2023年11月24日 | 9692 |
43+
| 8 | 2023年11月03日 | 5117 |
44+
| 1 | 2023年11月16日 | 5241 |
45+
| 10 | 2023年11月12日 | 8266 |
46+
| 13 | 2023年11月24日 | 12000 |
47+
+---------+---------------+--------------+
48+
<strong>Output:</strong>
49+
+---------------+---------------+--------------+
50+
| week_of_month | purchase_date | total_amount |
51+
+---------------+---------------+--------------+
52+
| 1 | 2023年11月03日 | 5117 |
53+
| 2 | 2023年11月10日 | 0 |
54+
| 3 | 2023年11月17日 | 0 |
55+
| 4 | 2023年11月24日 | 21692 |
56+
+---------------+---------------+--------------+
57+
<strong>Explanation:</strong>
58+
- During the first week of November 2023, transactions amounting to 5,117ドル occurred on Friday, 2023年11月03日.
59+
- For the second week of November 2023, there were no transactions on Friday, 2023年11月10日, resulting in a value of 0 in the output table for that day.
60+
- Similarly, during the third week of November 2023, there were no transactions on Friday, 2023年11月17日, reflected as 0 in the output table for that specific day.
61+
- In the fourth week of November 2023, two transactions took place on Friday, 2023年11月24日, amounting to 12,000ドル and 9,692ドル respectively, summing up to a total of 21,692ドル.
62+
Output table is ordered by week_of_month in ascending order.</pre>
63+
64+
## 解法
65+
66+
<!-- 这里可写通用的实现逻辑 -->
67+
68+
<!-- tabs:start -->
69+
70+
### **SQL**
71+
72+
<!-- 这里可写当前语言的特殊实现逻辑 -->
73+
74+
```sql
75+
76+
```
77+
78+
<!-- tabs:end -->
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# [2994. Friday Purchases II](https://leetcode.com/problems/friday-purchases-ii)
2+
3+
[中文文档](/solution/2900-2999/2994.Friday%20Purchases%20II/README.md)
4+
5+
## Description
6+
7+
<p>Table: <code>Purchases</code></p>
8+
9+
<pre>
10+
+---------------+------+
11+
| Column Name | Type |
12+
+---------------+------+
13+
| user_id | int |
14+
| purchase_date | date |
15+
| amount_spend | int |
16+
+---------------+------+
17+
(user_id, purchase_date, amount_spend) is the primary key (combination of columns with unique values) for this table.
18+
purchase_date will range from November 1, 2023, to November 30, 2023, inclusive of both dates.
19+
Each row contains user id, purchase date, and amount spend.
20+
</pre>
21+
22+
<p>Write a solution to calculate the <strong>total spending</strong> by users on <strong>each Friday</strong> of <strong>every week</strong> in <strong>November 2023</strong>. If there are <strong>no</strong> purchases on a particular <strong>Friday of a week</strong>, it will be considered as <code>0</code>.</p>
23+
24+
<p>Return <em>the result table ordered by week of month</em><em> in <strong>ascending</strong></em><em><strong> </strong>order.</em></p>
25+
26+
<p>The 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:</strong>
33+
Purchases table:
34+
+---------+---------------+--------------+
35+
| user_id | purchase_date | amount_spend |
36+
+---------+---------------+--------------+
37+
| 11 | 2023年11月07日 | 1126 |
38+
| 15 | 2023年11月30日 | 7473 |
39+
| 17 | 2023年11月14日 | 2414 |
40+
| 12 | 2023年11月24日 | 9692 |
41+
| 8 | 2023年11月03日 | 5117 |
42+
| 1 | 2023年11月16日 | 5241 |
43+
| 10 | 2023年11月12日 | 8266 |
44+
| 13 | 2023年11月24日 | 12000 |
45+
+---------+---------------+--------------+
46+
<strong>Output:</strong>
47+
+---------------+---------------+--------------+
48+
| week_of_month | purchase_date | total_amount |
49+
+---------------+---------------+--------------+
50+
| 1 | 2023年11月03日 | 5117 |
51+
| 2 | 2023年11月10日 | 0 |
52+
| 3 | 2023年11月17日 | 0 |
53+
| 4 | 2023年11月24日 | 21692 |
54+
+---------------+---------------+--------------+
55+
<strong>Explanation:</strong>
56+
- During the first week of November 2023, transactions amounting to 5,117ドル occurred on Friday, 2023年11月03日.
57+
- For the second week of November 2023, there were no transactions on Friday, 2023年11月10日, resulting in a value of 0 in the output table for that day.
58+
- Similarly, during the third week of November 2023, there were no transactions on Friday, 2023年11月17日, reflected as 0 in the output table for that specific day.
59+
- In the fourth week of November 2023, two transactions took place on Friday, 2023年11月24日, amounting to 12,000ドル and 9,692ドル respectively, summing up to a total of 21,692ドル.
60+
Output table is ordered by week_of_month in ascending order.</pre>
61+
62+
## Solutions
63+
64+
<!-- tabs:start -->
65+
66+
### **SQL**
67+
68+
```sql
69+
70+
```
71+
72+
<!-- tabs:end -->
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# [2995. 观众变主播](https://leetcode.cn/problems/viewers-turned-streamers)
2+
3+
[English Version](/solution/2900-2999/2995.Viewers%20Turned%20Streamers/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>表:&nbsp;<code>Sessions</code></p>
10+
11+
<pre>
12+
+---------------+----------+
13+
| Column Name | Type |
14+
+---------------+----------+
15+
| user_id | int |
16+
| session_start | datetime |
17+
| session_end | datetime |
18+
| session_id | int |
19+
| session_type | enum |
20+
+---------------+----------+
21+
session_id 是这张表具有唯一值的列。
22+
session_type 是一个 ENUM (枚举) 类型,包含(Viewer, Streamer)两个类别。
23+
这张表包含 user id, session start, session end, session id 和 session type。
24+
</pre>
25+
26+
<p>编写一个解决方案,找到&nbsp;<strong>首次会话&nbsp;</strong>为 <strong>观众</strong> 的用户的&nbsp;<strong>会话&nbsp;</strong>数量。</p>
27+
28+
<p>按照会话数量和 <code>user_id</code> <strong>降序</strong> 排序返回结果表。</p>
29+
30+
<p>结果格式如下例所示。</p>
31+
32+
<p>&nbsp;</p>
33+
34+
<p><b>示例 1:</b></p>
35+
36+
<pre>
37+
<b>输入:</b>
38+
Sessions table:
39+
+---------+---------------------+---------------------+------------+--------------+
40+
| user_id | session_start | session_end | session_id | session_type |
41+
+---------+---------------------+---------------------+------------+--------------+
42+
| 101 | 2023年11月06日 13:53:42 | 2023年11月06日 14:05:42 | 375 | Viewer |
43+
| 101 | 2023年11月22日 16:45:21 | 2023年11月22日 20:39:21 | 594 | Streamer |
44+
| 102 | 2023年11月16日 13:23:09 | 2023年11月16日 16:10:09 | 777 | Streamer |
45+
| 102 | 2023年11月17日 13:23:09 | 2023年11月17日 16:10:09 | 778 | Streamer |
46+
| 101 | 2023年11月20日 07:16:06 | 2023年11月20日 08:33:06 | 315 | Streamer |
47+
| 104 | 2023年11月27日 03:10:49 | 2023年11月27日 03:30:49 | 797 | Viewer |
48+
| 103 | 2023年11月27日 03:10:49 | 2023年11月27日 03:30:49 | 798 | Streamer |
49+
+---------+---------------------+---------------------+------------+--------------+
50+
<b>输出:</b>
51+
+---------+----------------+
52+
| user_id | sessions_count |
53+
+---------+----------------+
54+
| 101 | 2 |
55+
+---------+----------------+
56+
<b>解释</b>
57+
- user_id 101,在 2023年11月06日 13:53:42 以观众身份开始了他们的初始会话,随后进行了两次主播会话,所以计数为 2。
58+
- user_id 102,尽管有两个会话,但初始会话是作为主播,因此将排除此用户。
59+
- user_id 103 只参与了一次会话,即作为主播,因此不会考虑在内。
60+
- User_id 104 以观众身份开始了他们的第一次会话,但没有后续会话,因此不会包括在最终计数中。
61+
输出表按照会话数量和 user_id 降序排序。
62+
</pre>
63+
64+
## 解法
65+
66+
<!-- 这里可写通用的实现逻辑 -->
67+
68+
<!-- tabs:start -->
69+
70+
### **SQL**
71+
72+
<!-- 这里可写当前语言的特殊实现逻辑 -->
73+
74+
```sql
75+
76+
```
77+
78+
<!-- tabs:end -->

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /