task TRIM / LOWER / SUBSTR / REPLACE · medium
Parse malformed product codes
Normalize raw_code by trimming ASCII spaces and uppercasing it. Keep only codes of the exact form HM-DDDD-AA, where DDDD is four ASCII digits representing 1–9999 and AA is two ASCII letters. Return import_id, integer item_number and uppercase region.
what to return
- Columns
import_iditem_numberregionin this order- Rows
- 11 rows · in the order asked
- Watch for
- Reject NULL, 0000, extra characters, internal spaces and malformed delimiters. Order by import_id.
- Region is any pair of ASCII letters, not a lookup against a country list.
- Skill
- Normalize and validate a fixed-format identifier before parsing it. Refresher: CAST, text types & NULL arithmetic →
expected result
Your query should return exactly these columns and values. Run it and compare.
expected result11 rows · in this order
| import_id | item_number | region |
|---|---|---|
| 1 | 42 | US |
| 2 | 7 | GB |
| 8 | 9999 | JP |
first 3 of 11 rows
data you can query
Sample rows from each table. Each column shows its type underneath; → marks a link to another table.
market_raw_import4 columns · 19 rows
| idinteger · key | raw_codetext | raw_emailtext | raw_amounttext |
|---|---|---|---|
| 1 | hm-0042-us | Ana@Harbor.test | 19.99 |
| 2 | HM-0007-GB | ana@harbor.test | 0.29 |
| 3 | HM-12x4-US | Ben@harbor.test | -12.50 |
| 4 | HM-12345-US | BEN@HARBOR.TEST | +12 |
| 5 | HM-123-US | a@@harbor.test | 12x |
showing 5 of 19 rows
solution.sql
Hints and the answer are always available. Using them counts the question as solved with help.