task Validation & types · hard
Parse money into exact integer cents
For every import row, parse raw_amount into cents or NULL and label status valid or invalid. Trim outer ASCII spaces. Accept an optional leading + or -, one to six ASCII whole-number digits, and optionally a decimal point followed by one or two ASCII digits.
what to return
- Columns
import_idcentsstatusin this order- Rows
- 19 rows · in the order asked
- Watch for
- Leading zeros count toward the six-digit limit. Signed zero is valid. Missing whole digits, a trailing dot, exponents, separators, currency symbols and NULL are invalid.
- Use integer cents: 19.99 is 1999 and -0.29 is -29. No floating-point tolerance is intended. Return every row ordered by import_id.
- Skill
- Turn validated decimal text into exact integer minor units. Refresher: CAST, text types & NULL arithmetic →
expected result
Your query should return exactly these columns and values. Run it and compare.
expected result19 rows · in this order
| import_id | cents | status |
|---|---|---|
| 1 | 1999 | valid |
| 2 | 29 | valid |
| 3 | -1250 | valid |
first 3 of 19 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.