Calculate the Influence of Each Salesperson — LeetCode 2372 Python Solution
MediumLeetCode PremiumDatabase
- Problem
- #2372
- Reading time
- 3 min
- Source
- leetcode.com
Table schema
SQL
Table: Salesperson +----------------+---------+ | Column Name | Type | +----------------+---------+ | salesperson_id | int | | name | varchar | +----------------+---------+ salesperson_id contains unique values. Each row in this table shows the ID of a salesperson.Example
SQL
+----------------+---------+
| Column Name | Type |
+----------------+---------+
| salesperson_id | int |
| name | varchar |
+----------------+---------+
salesperson_id contains unique values.
Each row in this table shows the ID of a salesperson.Python solution
Python
import duckdb
import pandas as pd
def solution(salesperson: pd.DataFrame, customer: pd.DataFrame, sales: pd.DataFrame) -> pd.DataFrame:
con = duckdb.connect()
con.register("Salesperson", salesperson)
con.register("Customer", customer)
con.register("Sales", sales)
return con.execute("""SELECT sp.salesperson_id, name, IFNULL(SUM(price), 0) AS total
FROM
Salesperson AS sp
LEFT JOIN Customer AS c ON sp.salesperson_id = c.salesperson_id
LEFT JOIN Sales AS s ON s.customer_id = c.customer_id
GROUP BY 1;""").df()Complexity
| Measure | Complexity |
|---|---|
| Time | O(n log n) (typical) |
| Space | O(n) auxiliary |
Related problems
Frequently asked questions
- How hard is LeetCode 2372. Calculate the Influence of Each Salesperson?
- LeetCode 2372. Calculate the Influence of Each Salesperson is rated Medium on LeetCode.
- What topics does LeetCode 2372. Calculate the Influence of Each Salesperson cover?
- LeetCode 2372. Calculate the Influence of Each Salesperson is tagged Database on LeetCode.
- Is LeetCode 2372. Calculate the Influence of Each Salesperson a premium problem?
- Yes. LeetCode 2372. Calculate the Influence of Each Salesperson is a LeetCode Premium problem, so the full statement and test cases require a paid LeetCode subscription.