Loading problem...
A retail analytics team receives product-sale rows typed manually by different operators. The same product can appear with inconsistent case and extra spaces, which breaks monthly trend dashboards.
Table: sales
Canonicalization rules:
Task: Count sales per (canonical product_name, reporting month).
Output requirements:
Supported submission environments:
sales:
| sale_id | product_name | sale_date |
|---------|----------------|-------------|
| 1 | LCPHONE | 2020-01-16 |
| 2 | LCPhone | 2020-01-17 |
| 3 | LcPhOnE | 2020-02-18 |
| 4 | LCKeyCHAiN | 2020-02-19 |
| 5 | LCKeyChain | 2020-02-28 |
| 6 | Matryoshka | 2020-03-31 |[
{"product_name":"lckeychain","sale_month":"2020-02","total":2},
{"product_name":"lcphone","sale_month":"2020-01","total":2},
{"product_name":"lcphone","sale_month":"2020-02","total":1},
{"product_name":"matryoshka","sale_month":"2020-03","total":1}
]Case and surrounding spaces are normalized before grouping. Two January rows map to lcphone, and two February rows map to lckeychain.
sales:
| sale_id | product_name | sale_date |
|---------|---------------------|-------------|
| 10 | Noise Canceler | 2024-01-01 |
| 11 | noise canceler | 2024-01-09 |
| 12 | Noise Canceler | 2024-02-02 |
| 13 | Smart Plug | 2024-01-11 |
| 14 | smart plug | 2024-01-15 |[
{"product_name":"noise canceler","sale_month":"2024-01","total":2},
{"product_name":"noise canceler","sale_month":"2024-02","total":1},
{"product_name":"smart plug","sale_month":"2024-01","total":2}
]Rows are grouped by canonicalized names and month buckets extracted from sale_date.
sales:
| sale_id | product_name | sale_date |
|---------|--------------|-------------|
| 20 | Gadget | 2023-12-31 |
| 21 | gadget | 2024-01-01 |
| 22 | GADGET | 2024-01-02 |
| 23 | Cable | 2024-01-03 |[
{"product_name":"cable","sale_month":"2024-01","total":1},
{"product_name":"gadget","sale_month":"2023-12","total":1},
{"product_name":"gadget","sale_month":"2024-01","total":2}
]Month extraction is independent per row date, so year transitions are handled naturally.
Constraints