Before you start
You need Workbench and a running SQL engine. Every example includes its own input rows. No catalog, files, credentials, or external data is needed. These queries create no stored tables. Copy the SQL into Workbench and run the statements in order. Compare the result with the table below the query.WITH names input data for one statement only. Each example can run on its own.
1. Find missing values
Which item has no label?
Use IS NULL to test a missing value.
Change one thing: Use IS NOT NULL. Expect IDs 1, 3, and 4.
2. Supply a label
How can we display an unknown label?
COALESCE returns the first non-null argument.
Change one thing: Replace Unknown with Unassigned. Item 2 uses that label.
3. Count present values
How many amounts are present?
COUNT(*) counts rows. COUNT(column) skips nulls.
Change one thing: Count label instead. The present count is still 3.
4. Turn zero into NULL
Which amounts remain when zero means missing?
NULLIF returns NULL when its arguments are equal.
Change one thing: Use NULLIF(amount, 20). Item 1 becomes NULL and item 3 stays zero.
5. Filter nullable data
Which amounts are positive?
A null comparison is not true, so WHERE removes it.
Change one thing: Use amount >= 0. Item 3 also appears.
6. Control null ordering
Can missing amounts appear last?
NULLS LAST makes the position of missing values explicit.
Change one thing: Use NULLS FIRST. Item 2 moves to the top.