Skip to content

Commit da1778f

Browse files
authored
feat: add sql solutions to lc problems: No.2362 (doocs#1147)
* No.2362.Generate the Invoice * No.2372.Calculate the Influence of Each Salesperson
1 parent 494c41d commit da1778f

File tree

6 files changed

+78
-4
lines changed

6 files changed

+78
-4
lines changed

solution/2300-2399/2362.Generate the Invoice/README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,25 @@ Purchases 表:
9292
<!-- 这里可写当前语言的特殊实现逻辑 -->
9393

9494
```sql
95-
95+
# Write your MySQL query statement below
96+
WITH
97+
P AS (
98+
SELECT *
99+
FROM
100+
Purchases
101+
JOIN Products USING (product_id)
102+
),
103+
T AS (
104+
SELECT invoice_id, sum(price * quantity) AS amount
105+
FROM P
106+
GROUP BY invoice_id
107+
ORDER BY 2 DESC, 1
108+
LIMIT 1
109+
)
110+
SELECT product_id, quantity, (quantity * price) AS price
111+
FROM
112+
P
113+
JOIN T USING (invoice_id);
96114
```
97115

98116
<!-- tabs:end -->

solution/2300-2399/2362.Generate the Invoice/README_EN.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,25 @@ The highest price is 1000, and the invoices with the highest prices are 2 and 4.
8686
### **SQL**
8787

8888
```sql
89-
89+
# Write your MySQL query statement below
90+
WITH
91+
P AS (
92+
SELECT *
93+
FROM
94+
Purchases
95+
JOIN Products USING (product_id)
96+
),
97+
T AS (
98+
SELECT invoice_id, sum(price * quantity) AS amount
99+
FROM P
100+
GROUP BY invoice_id
101+
ORDER BY 2 DESC, 1
102+
LIMIT 1
103+
)
104+
SELECT product_id, quantity, (quantity * price) AS price
105+
FROM
106+
P
107+
JOIN T USING (invoice_id);
90108
```
91109

92110
<!-- tabs:end -->
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Write your MySQL query statement below
2+
WITH
3+
P AS (
4+
SELECT *
5+
FROM
6+
Purchases
7+
JOIN Products USING (product_id)
8+
),
9+
T AS (
10+
SELECT invoice_id, sum(price * quantity) AS amount
11+
FROM P
12+
GROUP BY invoice_id
13+
ORDER BY 2 DESC, 1
14+
LIMIT 1
15+
)
16+
SELECT product_id, quantity, (quantity * price) AS price
17+
FROM
18+
P
19+
JOIN T USING (invoice_id);

solution/2300-2399/2372.Calculate the Influence of Each Salesperson/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,13 @@ Jerry 的总数是 0。</pre>
121121
<!-- 这里可写当前语言的特殊实现逻辑 -->
122122

123123
```sql
124-
124+
# Write your MySQL query statement below
125+
SELECT sp.salesperson_id, name, ifnull(sum(price), 0) AS total
126+
FROM
127+
Salesperson AS sp
128+
LEFT JOIN Customer AS c ON sp.salesperson_id = c.salesperson_id
129+
LEFT JOIN Sales AS s ON s.customer_id = c.customer_id
130+
GROUP BY 1;
125131
```
126132

127133
<!-- tabs:end -->

solution/2300-2399/2372.Calculate the Influence of Each Salesperson/README_EN.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,13 @@ The total for Jerry is 0.
117117
### **SQL**
118118

119119
```sql
120-
120+
# Write your MySQL query statement below
121+
SELECT sp.salesperson_id, name, ifnull(sum(price), 0) AS total
122+
FROM
123+
Salesperson AS sp
124+
LEFT JOIN Customer AS c ON sp.salesperson_id = c.salesperson_id
125+
LEFT JOIN Sales AS s ON s.customer_id = c.customer_id
126+
GROUP BY 1;
121127
```
122128

123129
<!-- tabs:end -->
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Write your MySQL query statement below
2+
SELECT sp.salesperson_id, name, ifnull(sum(price), 0) AS total
3+
FROM
4+
Salesperson AS sp
5+
LEFT JOIN Customer AS c ON sp.salesperson_id = c.salesperson_id
6+
LEFT JOIN Sales AS s ON s.customer_id = c.customer_id
7+
GROUP BY 1;

0 commit comments

Comments
 (0)