Flag large transactions, keep refunds · SQL
Task: the 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)
Tab inserts spaces. Press Escape, then Tab, to move focus out of the editor.
| # | idstring | typestring | amountstring |
|---|---|---|---|
| 1 | twnh2 | sale | 128.99 |
| 2 | tthzj | sale | 3529 |
| 3 | tkv8b | sale | 8988.5 |
| 4 | two43 | sale | 280.05 |
| 5 | tgsij | sale | 11052.01 |
| 6 | t958j | refund | -3290.10 |
| 7 | tbd8e | sale | 2294.10 |
| 8 | tu51r | sale | 1710.05 |
| 9 | thfhm | sale | 5000.00 |
Run preview · in your browser, not a grade
Loading the preview runtime…
Check answer · graded on an isolated server, including hidden datasets
Your code runs in a locked-down machine with no network, on the visible data and on hidden datasets that follow the same rules.
Learn from this exercise
A worked solution becomes available after your first check or once you've used every hint.