Skip to content

Commit 6bc341c

Browse files
committed
feat(leetcode/medium/2372-calculate-the-influence-of-each-salesperson.sql)
1 parent 794a95e commit 6bc341c

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# leetcode/medium/2372. Calculate the Influence of Each Salesperson
2+
# 2372-calculate-the-influence-of-each-salesperson
3+
# URL: https://leetcode.com/problems/calculate-the-influence-of-each-salesperson/description/
4+
5+
# Input:
6+
# Salesperson table:
7+
# +----------------+-------+
8+
# | salesperson_id | name |
9+
# +----------------+-------+
10+
# | 1 | Alice |
11+
# | 2 | Bob |
12+
# | 3 | Jerry |
13+
# +----------------+-------+
14+
# Customer table:
15+
# +-------------+----------------+
16+
# | customer_id | salesperson_id |
17+
# +-------------+----------------+
18+
# | 1 | 1 |
19+
# | 2 | 1 |
20+
# | 3 | 2 |
21+
# +-------------+----------------+
22+
# Sales table:
23+
# +---------+-------------+-------+
24+
# | sale_id | customer_id | price |
25+
# +---------+-------------+-------+
26+
# | 1 | 2 | 892 |
27+
# | 2 | 1 | 354 |
28+
# | 3 | 3 | 988 |
29+
# | 4 | 3 | 856 |
30+
# +---------+-------------+-------+
31+
# Output:
32+
# +----------------+-------+-------+
33+
# | salesperson_id | name | total |
34+
# +----------------+-------+-------+
35+
# | 1 | Alice | 1246 |
36+
# | 2 | Bob | 1844 |
37+
# | 3 | Jerry | 0 |
38+
# +----------------+-------+-------+
39+
40+
SELECT s.salesperson_id, s.name, IFNULL(SUM(price), 0) AS total
41+
FROM Salesperson s
42+
LEFT JOIN Customer c ON s.salesperson_id = c.salesperson_id
43+
LEFT JOIN Sales s2 ON c.customer_id = s2.customer_id
44+
GROUP BY s.salesperson_id
45+
ORDER BY s.salesperson_id;

0 commit comments

Comments
 (0)