← SQL and spreadsheet practice

Excel / SQL data preparation · Original fictional case · Free files and answers

Audit ambiguous dates and mixed currencies

A travel-expense import mixes date conventions and currency labels. Produce an accepted ledger from the declared source convention, leaving ambiguous and unsupported records for review.

Suggested time: 15–25 minutes. All records, companies, rates and work policies are invented for this exercise.

Your output contract

  1. The supplied dates are valid calendar dates. DMY means day/month/year; MDY means month/day/year; ISO means YYYY-MM-DD. UNKNOWN must be held.
  2. amount_minor represents hundredths for the USD and EUR rows. The training rate is exactly EUR 1 = USD 1.10; it is fictional, not a market quote.
  3. Accept only declared dates and currencies in rates. Output expense_id,iso_date,usd_cents sorted by expense_id; retain zero expense E05.

Required columns: expense_id, iso_date, usd_cents. Row order is part of the contract. Empty output CSV fields represent NULL; zero remains 0.

Original source tables

expenses

6 source rows · Download expenses CSV

expense_id TEXTraw_date TEXTdate_format TEXTcurrency TEXTamount_minor INTEGER
E0111/04/2026DMYUSD12000
E0211/04/2026MDYUSD8500
E0311/04/2026UNKNOWNUSD5000
E042026-11-06ISOEUR7000
E052026-11-07ISOUSD0
E062026-11-08ISOJPY900

rates

2 source rows · Download rates CSV

currency TEXTusd_numerator INTEGERusd_denominator INTEGER
USD11
EUR1110

Plan the transformation

  1. Interpret E01 as 11 April and E02 as 4 November from their separate metadata.
  2. Hold E03 for a date convention and E06 for a missing currency policy.
  3. Join the declared rate and calculate integer cents. Keep rate assumptions beside the delivered file.

Watch for this mistake

A computer locale guesses a date convention. A currency symbol or an unlabeled number does not establish an exchange rate.

Run and check your SQLite result

The database runs locally in a worker. Use one SELECT or WITH query. Your query is saved on this device when storage is available. Download your SQL before clearing browser data.

Or work in Excel or another spreadsheet, then upload the final CSV with exactly the required columns.

Worked SQL and complete expected output

Accepted four rows total 28,200 USD cents. E03 and E06 are held, not silently converted.

SELECT e.expense_id,CASE date_format WHEN 'DMY' THEN substr(raw_date,7,4)||'-'||substr(raw_date,4,2)||'-'||substr(raw_date,1,2) WHEN 'MDY' THEN substr(raw_date,7,4)||'-'||substr(raw_date,1,2)||'-'||substr(raw_date,4,2) ELSE raw_date END iso_date,amount_minor*usd_numerator/usd_denominator usd_cents FROM expenses e JOIN rates r USING(currency) WHERE date_format IN ('DMY','MDY','ISO') ORDER BY expense_id;
expense_idiso_dateusd_cents
E012026-04-1112000
E022026-11-048500
E042026-11-067700
E052026-11-070

Download reference SQL · Download complete expected CSV · Download an empty answer CSV · Download SQLite setup

What to pass to a colleague

Keep the checked output and SQL or spreadsheet result. Explain the exception policy, the cross-check above and any held records. The checker confirms this fixed case’s output; it does not evaluate arbitrary private business data.

SQLite SELECT, joins and aggregation reference · Continue with the larger workplace projects

Try another case