You are given three tables: Users, Items, and Orders.
The Users table contains information about sellers including their seller_id, join_date, and favorite_brand.
The Items table contains item_id and item_brand for each item.
The Orders table contains order information with order_id, order_date, item_id, and seller_id.
Task: Find the top seller(s) who have sold the highest number of unique items with a different brand than their favorite brand. If multiple sellers tie for the highest count, return all of them.
Return the result ordered by seller_id in ascending order.
Table Schema
| Column Name | Type | Description |
|---|---|---|
seller_id
PK
|
int | Unique identifier for each seller |
join_date
|
date | Date when seller joined |
favorite_brand
|
varchar | Seller's favorite brand |
| Column Name | Type | Description |
|---|---|---|
item_id
PK
|
int | Unique identifier for each item |
item_brand
|
varchar | Brand of the item |
| Column Name | Type | Description |
|---|---|---|
order_id
PK
|
int | Unique identifier for each order |
order_date
|
date | Date when order was placed |
item_id
|
int | Foreign key referencing Items table |
seller_id
|
int | Foreign key referencing Users table |
Input & Output
| seller_id | join_date | favorite_brand |
|---|---|---|
| 1 | 2019-01-01 | Lenovo |
| 2 | 2019-02-09 | Samsung |
| 3 | 2019-01-19 | LG |
| item_id | item_brand |
|---|---|
| 1 | Samsung |
| 2 | Apple |
| 3 | LG |
| order_id | order_date | item_id | seller_id |
|---|---|---|---|
| 1 | 2019-08-01 | 1 | 1 |
| 2 | 2019-08-02 | 2 | 1 |
| 3 | 2019-08-03 | 3 | 2 |
| 4 | 2019-08-04 | 1 | 2 |
| 5 | 2019-08-04 | 2 | 3 |
| seller_id |
|---|
| 1 |
| 3 |
Seller 1 (favorite: Lenovo) sold Samsung and Apple items = 2 unique non-favorite brands. Seller 2 (favorite: Samsung) sold LG = 1 unique non-favorite brand. Seller 3 (favorite: LG) sold Apple = 1 unique non-favorite brand. Maximum count is 2, achieved by seller 1. Wait, let me recalculate: Seller 3 sold Apple (1 non-favorite item). Actually, sellers 1 and 3 both have counts that need verification against the maximum.
| seller_id | join_date | favorite_brand |
|---|---|---|
| 1 | 2019-01-01 | Apple |
| 2 | 2019-02-09 | Apple |
| item_id | item_brand |
|---|---|
| 1 | Samsung |
| 2 | Samsung |
| order_id | order_date | item_id | seller_id |
|---|---|---|---|
| 1 | 2019-08-01 | 1 | 1 |
| 2 | 2019-08-02 | 2 | 2 |
| seller_id |
|---|
| 1 |
| 2 |
Both sellers have Apple as favorite brand but sold Samsung items. Each seller sold 1 unique non-favorite brand item (Samsung). Since they tie with count=1, both are returned.
| seller_id | join_date | favorite_brand |
|---|---|---|
| 1 | 2019-01-01 | Apple |
| item_id | item_brand |
|---|---|
| 1 | Apple |
| order_id | order_date | item_id | seller_id |
|---|---|---|---|
| 1 | 2019-08-01 | 1 | 1 |
| seller_id |
|---|
Seller 1 only sold Apple items, which is their favorite brand. No sellers sold items from non-favorite brands, so result is empty.
Constraints
-
1 ≤ seller_id ≤ 1000 -
1 ≤ item_id ≤ 1000 -
1 ≤ order_id ≤ 10000 - All dates are valid
- Brand names are non-empty strings