Given a table DailySales that contains sales data with columns for date_id, make_name, lead_id, and partner_id.
For each unique combination of date_id and make_name, find:
- The number of distinct lead_id's
- The number of distinct partner_id's
The table may contain duplicate rows, so you need to count only unique leads and partners for each date and product combination.
Return the result table in any order.
Table Schema
| Column Name | Type | Description |
|---|---|---|
date_id
|
date | Date of the sales transaction |
make_name
|
varchar | Name of the product sold (lowercase English letters only) |
lead_id
|
int | ID of the lead associated with the sale |
partner_id
|
int | ID of the partner associated with the sale |
Input & Output
| date_id | make_name | lead_id | partner_id |
|---|---|---|---|
| 2020-12-8 | toyota | 0 | 1 |
| 2020-12-8 | toyota | 1 | 0 |
| 2020-12-8 | toyota | 1 | 2 |
| 2020-12-7 | toyota | 0 | 2 |
| 2020-12-7 | honda | 1 | 2 |
| date_id | make_name | unique_leads | unique_partners |
|---|---|---|---|
| 2020-12-8 | toyota | 2 | 3 |
| 2020-12-7 | toyota | 1 | 1 |
| 2020-12-7 | honda | 1 | 1 |
For 2020-12-8, toyota: distinct leads are [0, 1] (2 unique) and distinct partners are [1, 0, 2] (3 unique). For 2020-12-7, toyota: only lead 0 and partner 2 appear. For 2020-12-7, honda: only lead 1 and partner 2 appear.
| date_id | make_name | lead_id | partner_id |
|---|---|---|---|
| 2020-12-8 | nissan | 0 | 1 |
| 2020-12-8 | nissan | 0 | 1 |
| 2020-12-8 | nissan | 0 | 1 |
| date_id | make_name | unique_leads | unique_partners |
|---|---|---|---|
| 2020-12-8 | nissan | 1 | 1 |
Despite having 3 identical rows, there is only 1 distinct lead (ID 0) and 1 distinct partner (ID 1) for the 2020-12-8, nissan combination. COUNT DISTINCT eliminates duplicates automatically.
Constraints
-
date_idis a valid date -
make_nameconsists of only lowercase English letters -
lead_idandpartner_idare non-negative integers - The table may contain duplicate rows