EasyNo. 1511LeetCode Premium
Customer Order Frequency — LeetCode 1511 Python Solution
- Topics
- Database
- Reading time
- 3 min
- Source
- leetcode.com
Table schema
Table: Customers +---------------+---------+ | Column Name | Type | +---------------+---------+ | customer_id | int | | name | varchar | | country | varchar | +---------------+---------+ customer_id is the column with unique values for this table. This table contains information about the customers in the company.Example
+---------------+---------+
| Column Name | Type |
+---------------+---------+
| customer_id | int |
| name | varchar |
| country | varchar |
+---------------+---------+
customer_id is the column with unique values for this table.
This table contains information about the customers in the company.Python solution
import duckdb
import pandas as pd
def solution(customers: pd.DataFrame, product: pd.DataFrame, orders: pd.DataFrame) -> pd.DataFrame:
con = duckdb.connect()
con.register("Customers", customers)
con.register("Product", product)
con.register("Orders", orders)
return con.execute("""SELECT customer_id, name
FROM
Orders
JOIN Product USING (product_id)
JOIN Customers USING (customer_id)
WHERE YEAR(order_date) = 2020
GROUP BY 1
HAVING
SUM(IF(MONTH(order_date) = 6, quantity * price, 0)) >= 100
AND SUM(IF(MONTH(order_date) = 7, quantity * price, 0)) >= 100;""").df()Complexity
- Time
- O(n log n)(typical)
- Space · auxiliary
- O(n)
Related problems
| No. | Problem | Difficulty |
|---|---|---|
| 0175 | Combine Two Tables | Easy |
| 0176 | Second Highest Salary | Medium |
| 0177 | Nth Highest Salary | Medium |
| 0178 | Rank Scores | Medium |
| 0180 | Consecutive Numbers | Medium |
| 0181 | Employees Earning More Than Their Managers | Easy |
Frequently asked questions
- How hard is LeetCode 1511. Customer Order Frequency?
LeetCode 1511. Customer Order Frequency is rated Easy on LeetCode.
- What topics does LeetCode 1511. Customer Order Frequency cover?
LeetCode 1511. Customer Order Frequency is tagged Database on LeetCode.
- Is LeetCode 1511. Customer Order Frequency a premium problem?
Yes. LeetCode 1511. Customer Order Frequency is a LeetCode Premium problem, so the full statement and test cases require a paid LeetCode subscription.