runtime
64 / 88

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_numberregion in 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_iditem_numberregion
142US
27GB
89999JP

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 · keyraw_codetextraw_emailtextraw_amounttext
1 hm-0042-us Ana@Harbor.test 19.99
2HM-0007-GBana@harbor.test0.29
3HM-12x4-US Ben@harbor.test -12.50
4HM-12345-US BEN@HARBOR.TEST +12
5HM-123-USa@@harbor.test12x

showing 5 of 19 rows

solution.sql
 

Hints and the answer are always available. Using them counts the question as solved with help.