Exercise · beginner · 10 min
Flag large transactions, keep refunds
Mark sales above a review threshold instead of deleting them, and keep negative refunds as valid rows.
The rules
These rules decide what a correct result is. Your answer is checked on this dataset and on hidden datasets that follow the same rules.
Input transactions(id, type, amount) — text. id is unique. type is sale or refund. amount is always valid: optional "-", digits, optionally "." and 1–2 digits. Refunds are negative. Rules amount: convert to an exact decimal with 2 places (12.5 means 12.50). needs_review: true when amount is greater than 5000.00, otherwise false. Keep every row. Large values are flagged, never removed or capped. Output (row order does not matter) clean(id text, type text, amount decimal(12,2), needs_review bool)
The data
transactions · 9 rows
| id | type | amount |
|---|---|---|
| twnh2 | sale | 128.99 |
| tthzj | sale | 3529 |
| tkv8b | sale | 8988.5 |
| two43 | sale | 280.05 |
| tgsij | sale | 11052.01 |
| t958j | refund | -3290.10 |
| tbd8e | sale | 2294.10 |
| tu51r | sale | 1710.05 |
| thfhm | sale | 5000.00 |
What you practise
- flags
- decimals
- outliers
Your answer is also checked on hidden datasets generated from the same rules.
Sign in to bookmark this and keep private notes.