Skip to content

Commit 63a2492

Browse files
committed
feat: add solutions to lc problems: No.2373~2376
* No.2373.Largest Local Values in a Matrix * No.2374.Node With Highest Edge Score * No.2375.Construct Smallest Number From DI String * No.2376.Count Special Integers
1 parent 1b5a4c0 commit 63a2492

37 files changed

+6904
-4747
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# [2372. Calculate the Influence of Each Salesperson](https://leetcode.cn/problems/calculate-the-influence-of-each-salesperson)
2+
3+
[English Version](/solution/2300-2399/2372.Calculate%20the%20Influence%20of%20Each%20Salesperson/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>Table: <code>Salesperson</code></p>
10+
11+
<pre>
12+
+----------------+---------+
13+
| Column Name | Type |
14+
+----------------+---------+
15+
| salesperson_id | int |
16+
| name | varchar |
17+
+----------------+---------+
18+
sales_person_id is the primary key for this table.
19+
Each row in this table shows the ID of a salesperson and the price of one unit.
20+
</pre>
21+
22+
<p>&nbsp;</p>
23+
24+
<p>Table: <code>Customer</code></p>
25+
26+
<pre>
27+
+----------------+------+
28+
| Column Name | Type |
29+
+----------------+------+
30+
| customer_id | int |
31+
| salesperson_id | int |
32+
+----------------+------+
33+
customer_id is the primary key for this table.
34+
salesperson_id is a foreign key from the Salesperson table.
35+
Each row in this table shows the ID of a customer and the ID of the salesperson
36+
</pre>
37+
38+
<p>&nbsp;</p>
39+
40+
<p>Table: <code>Sales</code></p>
41+
42+
<pre>
43+
+-------------+------+
44+
| Column Name | Type |
45+
+-------------+------+
46+
| sale_id | int |
47+
| customer_id | int |
48+
| price | int |
49+
+-------------+------+
50+
sale_id is the primary key for this table.
51+
customer_id is a foreign key from the Customer table.
52+
Each row in this table shows ID of a customer and the price they paid for the sale with sale_id.
53+
</pre>
54+
55+
<p>&nbsp;</p>
56+
57+
<p>Write an SQL query to report the sum of prices paid by the customers of each salesperson. If a salesperson does not have any customers, the total value should be <code>0</code>.</p>
58+
59+
<p>Return the result table in <strong>any order</strong>.</p>
60+
61+
<p>The query result format is shown in the following example.</p>
62+
63+
<p>&nbsp;</p>
64+
<p><strong>Example 1:</strong></p>
65+
66+
<pre>
67+
<strong>Input:</strong>
68+
Salesperson table:
69+
+----------------+-------+
70+
| salesperson_id | name |
71+
+----------------+-------+
72+
| 1 | Alice |
73+
| 2 | Bob |
74+
| 3 | Jerry |
75+
+----------------+-------+
76+
Customer table:
77+
+-------------+----------------+
78+
| customer_id | salesperson_id |
79+
+-------------+----------------+
80+
| 1 | 1 |
81+
| 2 | 1 |
82+
| 3 | 2 |
83+
+-------------+----------------+
84+
Sales table:
85+
+---------+-------------+-------+
86+
| sale_id | customer_id | price |
87+
+---------+-------------+-------+
88+
| 1 | 2 | 892 |
89+
| 2 | 1 | 354 |
90+
| 3 | 3 | 988 |
91+
| 4 | 3 | 856 |
92+
+---------+-------------+-------+
93+
<strong>Output:</strong>
94+
+----------------+-------+-------+
95+
| salesperson_id | name | total |
96+
+----------------+-------+-------+
97+
| 1 | Alice | 1246 |
98+
| 2 | Bob | 1844 |
99+
| 3 | Jerry | 0 |
100+
+----------------+-------+-------+
101+
<strong>Explanation:</strong>
102+
Alice is the salesperson for customers 1 and 2.
103+
- Customer 1 made one purchase with 354.
104+
- Customer 2 made one purchase with 892.
105+
The total for Alice is 354 + 892 = 1246.
106+
107+
Bob is the salesperson for customers 3.
108+
- Customer 1 made one purchase with 988 and 856.
109+
The total for Bob is 988 + 856 = 1844.
110+
111+
Jerry is not the salesperson of any customer.
112+
The total for Jerry is 0.
113+
</pre>
114+
115+
## 解法
116+
117+
<!-- 这里可写通用的实现逻辑 -->
118+
119+
<!-- tabs:start -->
120+
121+
### **SQL**
122+
123+
<!-- 这里可写当前语言的特殊实现逻辑 -->
124+
125+
```sql
126+
127+
```
128+
129+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# [2372. Calculate the Influence of Each Salesperson](https://leetcode.com/problems/calculate-the-influence-of-each-salesperson)
2+
3+
[中文文档](/solution/2300-2399/2372.Calculate%20the%20Influence%20of%20Each%20Salesperson/README.md)
4+
5+
## Description
6+
7+
<p>Table: <code>Salesperson</code></p>
8+
9+
<pre>
10+
+----------------+---------+
11+
| Column Name | Type |
12+
+----------------+---------+
13+
| salesperson_id | int |
14+
| name | varchar |
15+
+----------------+---------+
16+
sales_person_id is the primary key for this table.
17+
Each row in this table shows the ID of a salesperson and the price of one unit.
18+
</pre>
19+
20+
<p>&nbsp;</p>
21+
22+
<p>Table: <code>Customer</code></p>
23+
24+
<pre>
25+
+----------------+------+
26+
| Column Name | Type |
27+
+----------------+------+
28+
| customer_id | int |
29+
| salesperson_id | int |
30+
+----------------+------+
31+
customer_id is the primary key for this table.
32+
salesperson_id is a foreign key from the Salesperson table.
33+
Each row in this table shows the ID of a customer and the ID of the salesperson
34+
</pre>
35+
36+
<p>&nbsp;</p>
37+
38+
<p>Table: <code>Sales</code></p>
39+
40+
<pre>
41+
+-------------+------+
42+
| Column Name | Type |
43+
+-------------+------+
44+
| sale_id | int |
45+
| customer_id | int |
46+
| price | int |
47+
+-------------+------+
48+
sale_id is the primary key for this table.
49+
customer_id is a foreign key from the Customer table.
50+
Each row in this table shows ID of a customer and the price they paid for the sale with sale_id.
51+
</pre>
52+
53+
<p>&nbsp;</p>
54+
55+
<p>Write an SQL query to report the sum of prices paid by the customers of each salesperson. If a salesperson does not have any customers, the total value should be <code>0</code>.</p>
56+
57+
<p>Return the result table in <strong>any order</strong>.</p>
58+
59+
<p>The query result format is shown in the following example.</p>
60+
61+
<p>&nbsp;</p>
62+
<p><strong>Example 1:</strong></p>
63+
64+
<pre>
65+
<strong>Input:</strong>
66+
Salesperson table:
67+
+----------------+-------+
68+
| salesperson_id | name |
69+
+----------------+-------+
70+
| 1 | Alice |
71+
| 2 | Bob |
72+
| 3 | Jerry |
73+
+----------------+-------+
74+
Customer table:
75+
+-------------+----------------+
76+
| customer_id | salesperson_id |
77+
+-------------+----------------+
78+
| 1 | 1 |
79+
| 2 | 1 |
80+
| 3 | 2 |
81+
+-------------+----------------+
82+
Sales table:
83+
+---------+-------------+-------+
84+
| sale_id | customer_id | price |
85+
+---------+-------------+-------+
86+
| 1 | 2 | 892 |
87+
| 2 | 1 | 354 |
88+
| 3 | 3 | 988 |
89+
| 4 | 3 | 856 |
90+
+---------+-------------+-------+
91+
<strong>Output:</strong>
92+
+----------------+-------+-------+
93+
| salesperson_id | name | total |
94+
+----------------+-------+-------+
95+
| 1 | Alice | 1246 |
96+
| 2 | Bob | 1844 |
97+
| 3 | Jerry | 0 |
98+
+----------------+-------+-------+
99+
<strong>Explanation:</strong>
100+
Alice is the salesperson for customers 1 and 2.
101+
- Customer 1 made one purchase with 354.
102+
- Customer 2 made one purchase with 892.
103+
The total for Alice is 354 + 892 = 1246.
104+
105+
Bob is the salesperson for customers 3.
106+
- Customer 1 made one purchase with 988 and 856.
107+
The total for Bob is 988 + 856 = 1844.
108+
109+
Jerry is not the salesperson of any customer.
110+
The total for Jerry is 0.
111+
</pre>
112+
113+
## Solutions
114+
115+
<!-- tabs:start -->
116+
117+
### **SQL**
118+
119+
```sql
120+
121+
```
122+
123+
<!-- tabs:end -->

0 commit comments

Comments
 (0)