MediumNo. 2084LeetCode Premium
Drop Type 1 Orders for Customers With Type 0 Orders — LeetCode 2084 Python Solution
- Topics
- Database
- Reading time
- 3 min
- Source
- leetcode.com
Table schema
Table: Orders +-------------+------+ | Column Name | Type | +-------------+------+ | order_id | int | | customer_id | int | | order_type | int | +-------------+------+ order_id is the column with unique values for this table. Each row of this table indicates the ID of an order, the ID of the customer who ordered it, and the order type.Example
+-------------+------+
| Column Name | Type |
+-------------+------+
| order_id | int |
| customer_id | int |
| order_type | int |
+-------------+------+
order_id is the column with unique values for this table.
Each row of this table indicates the ID of an order, the ID of the customer who ordered it, and the order type.
The orders could be of type 0 or type 1.Python solution
import duckdb
import pandas as pd
def solution(orders: pd.DataFrame) -> pd.DataFrame:
con = duckdb.connect()
con.register("Orders", orders)
return con.execute("""WITH
T AS (
SELECT DISTINCT customer_id
FROM Orders
WHERE order_type = 0
)
SELECT *
FROM Orders AS o
WHERE order_type = 0 OR NOT EXISTS (SELECT 1 FROM T AS t WHERE t.customer_id = o.customer_id);""").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 2084. Drop Type 1 Orders for Customers With Type 0 Orders?
LeetCode 2084. Drop Type 1 Orders for Customers With Type 0 Orders is rated Medium on LeetCode.
- What topics does LeetCode 2084. Drop Type 1 Orders for Customers With Type 0 Orders cover?
LeetCode 2084. Drop Type 1 Orders for Customers With Type 0 Orders is tagged Database on LeetCode.
- Is LeetCode 2084. Drop Type 1 Orders for Customers With Type 0 Orders a premium problem?
Yes. LeetCode 2084. Drop Type 1 Orders for Customers With Type 0 Orders is a LeetCode Premium problem, so the full statement and test cases require a paid LeetCode subscription.