Data Cleaning Exercises

Reference · SQL (DuckDB)

Flag rows in SQL (DuckDB)

Add a true/false column that marks rows matching a condition, keeping every row.

When to use it

Unusual but possibly legitimate values that need human review.

How

A boolean expression in the SELECT list.

CAST(amount AS DECIMAL(12,2)) > 5000.00 AS needs_review
  • Use COALESCE(..., false) if missing values must be false rather than NULL.

Pitfalls

  • Deleting or capping instead of flagging.
  • Getting the boundary wrong (> versus >=).

Lesson: Flag outliers, don't delete them

Practise it: Flag large transactions, keep refunds