TOPIC 18/3015 MINNOT STARTED

SQL for BAs: CASE, dates and text

Real data needs grouping into bands, cleaning text and working with dates. Learn the small functions that do most of the work.

L1–L4 are part of the Pro pass

L0 Explain simply

Analogy: sorting laundry. You put clothes in piles by rules: whites, then darks, then delicates. A garment goes to the first pile whose rule fits. Before that, you empty pockets and fix labels.

Daily List is a made-up to-do app (SYNTHETIC / TRAINING ONLY). Sam, the , labels tasks by due date, groups them by month, and cleans a tag that was typed three ways.

What it is: (Structured Query Language) can calculate a new value for each row. A table is a grid, a row is one record, and a column is one fact. A picks a value from rules, and the first true WHEN wins. Date parts and truncation cut a date down to a month or count the days between two dates. Text cleaning trims spaces and flattens case before you group. CASE is not a filter. WHERE drops rows. CASE labels the rows you still have. Those two are the neighbours.

Why it matters: Nina's tag report shows Work and work as two tags. They are one tag with a space and a capital. A month count that uses the wrong function name does not run at all.

A can move a timestamp across midnight. These examples use plain dates, with no clock time.

PLAIN WORDS · 1 in this section
flattens
makes level or smooth

PICTURE IT

The picture is the one the lesson above opens with. The table below shows how each part of it matches the work.

THE REAL JOB Sorting laundry into piles by rules after tidying.

  1. Tidy
  2. Sort
  3. Label
Laundry piles

HOW THE PICTURE MAPS

How each part of the picture matches the work
In the pictureIn the work
The pilesCASE results
Shaking out pocketsText cleaning
A tag on the shirtA date part
The first pile that fitsThe first true WHEN

WHERE THIS PICTURE STOPS

  • Laundry is physical, but rows are data.
  • A pile is chosen once, but rules can change.
  • A shirt is seen, but spaces in text are hidden.

HOOK

Tidy, sort, label.

TELL A FRIEND

Laundry: tidy first, then sort by rules.

OFTEN MIXED UP WITH SQL for BAs: NULL and missing values. That topic explains blank values. This one covers the functions that band, date and clean data.

PRACTISE AND KEEP

Sources for this topic — 5 sources
  1. Market practice

    Conditional expressions (PostgreSQL documentation) ↗ — PostgreSQL · PostgreSQL 18, §9.18 CASE/COALESCE/NULLIF; publisher page opened6November 2026. Dialect scope explicit.

    §9.18 CASE/COALESCE/NULLIF. PostgreSQL18 implementation, not a universal SQL mandate. · Checked 2026-11-06

    PostgreSQL18 publisher documentation opened on6November2026: §9.18 CASE/COALESCE/NULLIF. No execution on PostgreSQL is claimed; engine-specific examples remain scoped to18.

  2. Market practice

    PostgreSQL18: date/time functions ↗ — PostgreSQL Global Development Group · PostgreSQL 18: date/time functions; §9.9 typed date arithmetic and truncation/timezones. Publisher page opened6November 2026.

    §9.9 typed date arithmetic and truncation/timezones. · Checked 2026-11-06

    Publisher documentation opened on6November2026. Engine/version scope is explicit; other database implementations may differ. Teaching queries are synthetic, not a required publisher template.

  3. Market practice

    Pattern matching (PostgreSQL documentation) ↗ — PostgreSQL · PostgreSQL 18, §9.7 LIKE/ILIKE, escaping and collation scope; publisher page opened6November 2026. Dialect scope explicit.

    §9.7 LIKE/ILIKE, escaping and collation scope. PostgreSQL18 implementation, not a universal SQL mandate. · Checked 2026-11-06

    PostgreSQL18 publisher documentation opened on6November2026: §9.7 LIKE/ILIKE, escaping and collation scope. No execution on PostgreSQL is claimed; engine-specific examples remain scoped to18.

  4. Market practice

    SQLite: date/time functions ↗ — SQLite project · SQLite: date/time functions; ISO text/julianday/date modifiers, numeric subtraction contrast. Publisher page opened6November 2026.

    ISO text/julianday/date modifiers, numeric subtraction contrast. · Checked 2026-11-06

    Publisher documentation opened on6November2026. Engine/version scope is explicit; other database implementations may differ. Teaching queries are synthetic, not a required publisher template.

  5. Simplified educational illustration

    Payments Signal editorial teaching models — Payments Signal

    This site's own simplified teaching models. · Checked 2026-07-12

    What this simplifies: Daily List people, data and exercises are invented for teaching. Query results belong to the declared fixture and database version. Authorization, business identity, time bounds and unknown-value policy must be agreed in context; no universal mandatory query template is implied.

    Used wherever diagrams, scenarios, figures, or example values are didactic constructions rather than sourced facts; every such use carries a simplifications disclosure. All people, companies, banks, and list entries in examples are fictional.

Deepest material on this page: L4 — Standards & sources. Where a topic stops short of implementation depth, that is a deliberate coverage decision, not an oversight — see coverage.