MariaDB / Basic: relational foundations / Lesson 7
Classify rows with CASE and NULL
Build an explicit shipment-weight classification without confusing unknown values with zero.
On this page
Lesson goals
- Explain ordered CASE branches and NULL checks.
- Predict classifications for a synthetic fixture.
- Test boundaries and missing values against a business rule.
- Trace ordered and overlapping CASE predicates for known, missing and invalid values.
- Reconcile conditional category totals and preserve the meaning of missing inputs.
Define the classification
A harbor report needs to label shipments as heavy, standard, or unknown. A missing weight is not automatically zero: it can mean that weighing has not occurred. Define the threshold, unit, boundary inclusion, and missing-value meaning before writing SQL. A CASE expression returns a value for each row according to its conditions; it does not validate the original measurement or perform a physical weighing.
Create a synthetic lab table
The following SQL is illustrative for a new disposable MariaDB InnoDB lab. It creates three shipment rows with exact decimal weights, including one NULL. It does not access a configured application database. The training rule labels weights of at least ten kilograms heavy, lower known weights standard, and missing weights unknown. Real deployments need their own accepted ranges and measurement policy.
CREATE TABLE lab_shipments (id INT PRIMARY KEY, status VARCHAR(12) NOT NULL, weight_kg DECIMAL(6,2) NULL) ENGINE=InnoDB;
INSERT INTO lab_shipments VALUES (1, 'ready', 12.00), (2, 'pending', NULL), (3, 'ready', 5.00);
Shipment 1 weighs 12.00 kg, shipment 2 has an unknown weight, and shipment 3 weighs 5.00 kg. These are declared fixture facts rather than measured database output.
Classify each row
The CASE expression checks the missing case first with IS NULL, then checks the inclusive heavy boundary. ELSE handles remaining known weights in this constrained example. The final ORDER BY makes the display order explicit. In a real schema, validate negative or implausible values separately rather than silently calling every unexpected number standard.
SELECT id, status, weight_kg,
CASE WHEN weight_kg IS NULL THEN 'unknown'
WHEN weight_kg >= 10 THEN 'heavy' ELSE 'standard' END AS weight_class
FROM lab_shipments ORDER BY id;
The declared fixture yields heavy for id 1, unknown for id 2, and standard for id 3. The threshold and labels are business choices for this lab; no live result is asserted.
Test the edge cases
Add hypothetical values immediately below ten, exactly ten, and above ten, using the precision accepted by the schema. Predict their labels and verify them in a disposable test. Check that the query uses IS NULL rather than equality with NULL. If future rules distinguish zero, negative, or invalid values, add explicit validation and branches instead of relying on the existing ELSE.
Keep the report meaning visible
A classification is derived from the current stored weight and the current threshold. If a historical report must preserve the classification used at a past decision, document how the input, rule version, and decision are recorded. Test report totals at the intended row grain and compare unknown counts separately. Clear labels help users distinguish missing information from a measured value.
Define the measured domain
Before writing CASE, record what each stored value means. Here weight_kg is DECIMAL(6,2), measured in kilograms, and NULL means a shipment has not yet been weighed. A zero measurement is an actual known number, not the absence of a measurement. Decide separately whether zero is physically acceptable for the particular process. A reporting rule may classify it as standard, while an intake validation rule rejects it; mixing those two decisions hides data quality problems from operators. The examples use synthetic rows and reasoned results, not a connected server.
The report is at one row per shipment, so a classification expression should preserve that grain. State whether a rejected measurement receives an invalid label or is excluded from the report. If users need counts, reconcile the sum of the mutually exclusive categories with the count of shipments, and report the unknown and invalid counts separately. Changing a label does not change the underlying measurement or prove that the measurement was accurate.
Evaluate ordered branches
A searched CASE tests WHEN conditions from top to bottom and returns the result for the first condition that is true. FALSE and UNKNOWN do not select a branch. With an inclusive heavy threshold of 10.00, checking weight_kg >= 10 before weight_kg >= 20 would make a later very-heavy branch unreachable. Put more specific overlapping conditions first, or write explicit nonoverlapping intervals. Document the chosen order alongside its business rationale so a future threshold change does not silently swallow a category.
ELSE is a deliberate policy, not merely a syntactic convenience. Without ELSE, unmatched rows yield NULL; with ELSE 'standard', every unhandled row receives standard, including negative weights unless an earlier branch rejects them. A reviewer should list the intended domain and walk one representative input through every branch, including values that were not expected during development. Distinguish an unknown input from a known input that fails validation.
Understand unknown comparisons
SQL uses three-valued logic: a comparison with NULL produces UNKNOWN, rather than TRUE or FALSE. Consequently weight_kg = NULL does not find missing weights, and weight_kg <> NULL does not find known weights. Use IS NULL and IS NOT NULL. In a WHERE clause only TRUE retains a row; UNKNOWN is filtered out, which can make a report lose the very records it should identify as awaiting measurement.
COALESCE(weight_kg, 0) substitutes zero for NULL, but it changes the reporting meaning. It is appropriate only if the business rule explicitly treats absent measurement as zero for that calculation. Retain an indicator of missingness when downstream readers must distinguish it. A simple CASE comparing an expression to WHEN NULL also does not match a null value; a searched CASE with IS NULL expresses the missing branch directly.
Test precision and ranges
The column stores two decimal places, so 9.99, 10.00, and 10.01 are useful neighboring values for a ten-kilogram threshold. Under the stated inclusive rule they yield standard, heavy, and heavy respectively. The precise stored value matters: values supplied with greater precision may be rounded or rejected according to the column definition and server SQL mode. Do not infer classification from an input string before knowing what the database stored.
Add negative and implausibly large inputs to the test matrix when the system can receive them. A CASE expression classifies stored rows but is not a substitute for upstream validation or a schema constraint. If the threshold is changed to greater than ten, exactly 10.00 moves to standard; the values on both sides remain useful regression checks. Record the unit with the threshold so that grams are never compared against a kilograms rule without conversion.
Aggregate and preserve meaning
Conditional aggregation can count each category after classification. COUNT(*) counts every row, whereas COUNT(weight_kg) excludes missing measurements. SUM of a CASE that returns one or zero can count a named condition, but an empty input may produce NULL for SUM, so decide whether COALESCE is needed for an empty report. Compare category counts with COUNT(*) and investigate any difference rather than assuming the CASE covers every possibility.
For historical reporting, recalculating from today's weight or threshold can change yesterday's label. If the business requires the original decision, retain the approved input, rule version, and decision time under an agreed data policy. A current operational report can instead derive its labels dynamically, provided readers understand that later corrections change its results. Test both the row labels and totals in a disposable lab before releasing the report; the examples here are illustrative and have not been executed.
20 worked examples
1. Missing measurement
Problem: What label should an unweighed shipment receive?
- The fixture contains NULL rather than a measured weight.
- IS NULL is true for that value.
SELECT CASE WHEN NULL IS NULL THEN 'unknown' ELSE 'known' END;
unknown
Synthetic inputs and results are reasoned; this query has not been run against a qualified MariaDB server.
Why this result follows: The explicit missing branch keeps an unweighed shipment distinct from a zero measurement.
2. Inclusive threshold
Problem: How is a known 10.00 kg weight classified?
- The given measurement equals the threshold exactly.
- The greater-than-or-equal comparison includes equality.
SELECT CASE WHEN 10.00 >= 10 THEN 'heavy' ELSE 'standard' END;
heavy
Synthetic inputs and results are reasoned; this query has not been run against a qualified MariaDB server.
Why this result follows: The boundary belongs to heavy because the business rule explicitly includes ten.
3. Below threshold
Problem: Classify a known weight immediately below the boundary.
- The stored two-decimal measurement is below 10.
- The heavy predicate is false and ELSE applies.
SELECT CASE WHEN 9.99 >= 10 THEN 'heavy' ELSE 'standard' END;
standard
Synthetic inputs and results are reasoned; this query has not been run against a qualified MariaDB server.
Why this result follows: A neighboring decimal tests the lower side of the specified boundary.
4. Above threshold
Problem: Classify a measurement immediately above the boundary.
- The measurement exceeds the exact threshold.
- The heavy predicate evaluates true before ELSE.
SELECT CASE WHEN 10.01 >= 10 THEN 'heavy' ELSE 'standard' END;
heavy
Synthetic inputs and results are reasoned; this query has not been run against a qualified MariaDB server.
Why this result follows: This neighboring decimal confirms the upper side of the inclusive comparison.
5. Zero is known
Problem: Does a zero measurement mean the weight is missing?
- Zero is a known numeric value, not SQL NULL.
- It falls below ten and reaches the remaining known branch.
SELECT CASE WHEN 0.00 IS NULL THEN 'unknown' WHEN 0.00 >= 10 THEN 'heavy' ELSE 'standard' END;
standard
Synthetic inputs and results are reasoned; this query has not been run against a qualified MariaDB server.
Why this result follows: The lab rule treats zero as standard; a separate validation policy may reject it.
6. Reject a negative
Problem: How can a report expose an invalid negative measurement?
- The negative number is known so it bypasses unknown.
- The explicit negative branch precedes the normal categories.
SELECT CASE WHEN -1.00 IS NULL THEN 'unknown' WHEN -1.00 < 0 THEN 'invalid' WHEN -1.00 >= 10 THEN 'heavy' ELSE 'standard' END;
invalid
Synthetic inputs and results are reasoned; this query has not been run against a qualified MariaDB server.
Why this result follows: An invalid label avoids silently counting an impossible measurement as standard.
7. First true branch
Problem: What happens when broad and narrow branches overlap?
- Twenty-five satisfies both threshold predicates.
- The first true predicate determines the result.
SELECT CASE WHEN 25 >= 10 THEN 'heavy' WHEN 25 >= 20 THEN 'very heavy' ELSE 'standard' END;
heavy
Synthetic inputs and results are reasoned; this query has not been run against a qualified MariaDB server.
Why this result follows: The broad first branch makes the later very-heavy condition unreachable for this input.
8. Specific branch first
Problem: How can the very-heavy category remain reachable?
- The more selective twenty-kilogram test appears first.
- Twenty-five meets that test before the lower threshold is examined.
SELECT CASE WHEN 25 >= 20 THEN 'very heavy' WHEN 25 >= 10 THEN 'heavy' ELSE 'standard' END;
very heavy
Synthetic inputs and results are reasoned; this query has not been run against a qualified MariaDB server.
Why this result follows: Ordering overlapping ranges from most specific to broadest preserves the intended category.
9. Missing equality trap
Problem: What does a comparison of NULL with NULL produce?
- Neither operand represents a known comparable value.
- SQL equality therefore evaluates to UNKNOWN, displayed as NULL.
SELECT NULL = NULL AS equality_result;
NULL
Synthetic inputs and results are reasoned; this query has not been run against a qualified MariaDB server.
Why this result follows: An equality comparison does not establish whether a missing measurement is present.
10. Known value predicate
Problem: Which fixture rows have known weights?
- Rows 1 and 3 have numeric values in the fixture.
- IS NOT NULL excludes only the unmeasured second row.
WITH s AS (SELECT 1 id, 12.00 weight_kg UNION ALL SELECT 2, NULL UNION ALL SELECT 3, 5.00) SELECT id FROM s WHERE weight_kg IS NOT NULL ORDER BY id;
1; 3
Synthetic inputs and results are reasoned; this query has not been run against a qualified MariaDB server.
Why this result follows: The explicit null predicate filters known measurements without treating zero as absent.
11. Unknown filter loss
Problem: Which fixture rows survive a numeric WHERE predicate?
- Five is less than ten but twelve is not.
- The missing comparison is UNKNOWN and WHERE retains only TRUE.
WITH s AS (SELECT 1 id, 12.00 weight_kg UNION ALL SELECT 2, NULL UNION ALL SELECT 3, 5.00) SELECT id FROM s WHERE weight_kg < 10 ORDER BY id;
3
Synthetic inputs and results are reasoned; this query has not been run against a qualified MariaDB server.
Why this result follows: The missing row disappears unless the predicate explicitly includes IS NULL.
12. Preserve unknown in filter
Problem: How can a report include small and unmeasured shipments?
- The explicit missing condition retains shipment 2.
- Shipment 3 satisfies the numeric condition, while shipment 1 satisfies neither.
WITH s AS (SELECT 1 id, 12.00 weight_kg UNION ALL SELECT 2, NULL UNION ALL SELECT 3, 5.00) SELECT id FROM s WHERE weight_kg < 10 OR weight_kg IS NULL ORDER BY id;
2; 3
Synthetic inputs and results are reasoned; this query has not been run against a qualified MariaDB server.
Why this result follows: The OR expresses the two independent reasons a row should appear.
13. Simple CASE trap
Problem: Does WHEN NULL match a NULL simple CASE input?
- Simple CASE compares the input with each WHEN value.
- The NULL equality comparison is UNKNOWN rather than TRUE.
SELECT CASE NULL WHEN NULL THEN 'unknown' ELSE 'other' END;
other
Synthetic inputs and results are reasoned; this query has not been run against a qualified MariaDB server.
Why this result follows: Use searched CASE with IS NULL when a missing input needs its own label.
14. Missing ELSE
Problem: What results when no CASE branch matches and ELSE is omitted?
- Five does not satisfy the only given branch.
- There is no ELSE result to return.
SELECT CASE WHEN 5 >= 10 THEN 'heavy' END;
NULL
Synthetic inputs and results are reasoned; this query has not been run against a qualified MariaDB server.
Why this result follows: The CASE operator returns NULL for an unmatched condition without ELSE.
15. Default substitution
Problem: What value results from replacing a missing measurement with zero?
- The first argument is absent.
- COALESCE selects the next non-NULL argument, which is the numeric zero supplied here.
SELECT COALESCE(NULL, 0) AS weight_for_calculation;
0
Synthetic inputs and results are reasoned; this query has not been run against a qualified MariaDB server.
Why this result follows: Substitution produces a calculable zero but loses the original missingness unless preserved separately.
16. Retain missing indicator
Problem: How can the report expose a replacement and its origin?
- COALESCE supplies zero for the calculation.
- The independent IS NULL test records that the source was missing.
SELECT COALESCE(NULL, 0) AS value_used, CASE WHEN NULL IS NULL THEN 1 ELSE 0 END AS was_missing;
0 | 1
Synthetic inputs and results are reasoned; this query has not been run against a qualified MariaDB server.
Why this result follows: The indicator prevents the substituted zero from masquerading as a measured zero.
17. Count known values
Problem: How do total and known counts differ in the three-row fixture?
- COUNT(*) counts all three fixture rows.
- COUNT(weight_kg) excludes the one NULL value.
WITH s AS (SELECT 12.00 weight_kg UNION ALL SELECT NULL UNION ALL SELECT 5.00) SELECT COUNT(*) AS total, COUNT(weight_kg) AS known FROM s;
3 | 2
Synthetic inputs and results are reasoned; this query has not been run against a qualified MariaDB server.
Why this result follows: The difference measures missing values here because each row has one weight field.
18. Count heavy and missing
Problem: How can conditional aggregation count two distinct classes?
- Only 12.00 satisfies the heavy predicate.
- Only the NULL row satisfies the missing predicate.
WITH s AS (SELECT 12.00 weight_kg UNION ALL SELECT NULL UNION ALL SELECT 5.00) SELECT SUM(CASE WHEN weight_kg >= 10 THEN 1 ELSE 0 END) heavy, SUM(CASE WHEN weight_kg IS NULL THEN 1 ELSE 0 END) unknown_count FROM s;
1 | 1
Synthetic inputs and results are reasoned; this query has not been run against a qualified MariaDB server.
Why this result follows: Two separate conditional sums preserve the distinction between heavy and unweighed rows.
19. Empty aggregation
Problem: What does a conditional sum return for no input rows?
- The WHERE condition removes the only hypothetical row.
- SUM receives no values and produces NULL.
SELECT SUM(CASE WHEN weight_kg >= 10 THEN 1 ELSE 0 END) AS heavy FROM (SELECT 5.00 AS weight_kg) AS s WHERE 1=0;
NULL
Synthetic inputs and results are reasoned; this query has not been run against a qualified MariaDB server.
Why this result follows: The ELSE belongs to each input row and cannot supply a zero when no rows exist.
20. Empty report default
Problem: How can an empty report display zero heavy shipments?
- The empty input causes SUM to return NULL.
- The outer COALESCE substitutes zero for that aggregate result.
SELECT COALESCE(SUM(CASE WHEN weight_kg >= 10 THEN 1 ELSE 0 END), 0) AS heavy FROM (SELECT 5.00 AS weight_kg) AS s WHERE 1=0;
0
Synthetic inputs and results are reasoned; this query has not been run against a qualified MariaDB server.
Why this result follows: An explicit empty-report policy converts the absent aggregate to the desired count.
Common errors and fixes
A NULL weight is labeled standard.
- Why it happens
- The query compares with NULL using equality or omits an unknown branch.
- How to fix it
- Use IS NULL and define the unknown outcome.
- Prevent it next time
- Include missing values in report tests.
A ten-kilogram shipment is classified incorrectly.
- Why it happens
- The inclusive threshold was not specified or implemented consistently.
- How to fix it
- Use the comparison required by the business rule.
- Prevent it next time
- Test exact and neighboring boundary values.
A historical report changes classification unexpectedly.
- Why it happens
- It recalculates from a changed weight or threshold.
- How to fix it
- Use the approved historical input and rule record.
- Prevent it next time
- Document the reporting time and rule version.
20 practice exercises
1. What are the three classifications in the fixture?
Show hint
Apply missingness before the inclusive heavy threshold.
Show worked solution
Id 1 is heavy because 12.00 is at least ten; id 2 is unknown because the weight is NULL; id 3 is standard because 5.00 is known and below ten.
Shipment 1 has 12.00 and is heavy; shipment 2 has no measured weight and is unknown; shipment 3 has 5.00 and is standard. These labels derive from the stated fixture and rule.
Check your solution
- Id 1 is heavy and id 2 is unknown.
- Id 3 is standard because its weight is known and below ten.
2. How should a weight of exactly 10.00 be classified under the lab rule?
Show hint
Examine whether equality belongs to the heavy comparison.
Show worked solution
Heavy, because the CASE uses an inclusive greater-than-or-equal comparison. Test nearby values at the declared decimal precision too.
The rule uses >= 10, so exactly 10.00 is heavy. Testing 9.99 and 10.01 around it also shows which side each adjacent representable two-decimal value occupies.
Check your solution
- 10.00 is heavy.
- 9.99 is standard and 10.01 is heavy.
3. Classify 8.50, 10.00 and NULL under the inclusive ten-kilogram rule.
Show hint
Trace the stated values through the rule and distinguish missing from known.
Show worked solution
8.50 is standard, 10.00 is heavy and NULL is unknown. Test missingness first with IS NULL, then the inclusive threshold; the remaining known measurement falls into standard.
Check your solution
- 8.50 is standard; 10.00 is heavy
- NULL is unknown
4. A report marks NULL weights standard using ELSE. How should its CASE change?
Show hint
Trace the stated values through the rule and distinguish missing from known.
Show worked solution
Add WHEN weight_kg IS NULL THEN unknown before the numeric test. Comparisons with NULL are UNKNOWN, so the current branch falls through to ELSE. Preserve standard only for known values below the threshold.
Check your solution
- Add an IS NULL branch
- Known values below ten remain standard
5. A CASE checks >= 10 before >= 20. Repair the very-heavy classification for 22 kg.
Show hint
Trace the stated values through the rule and distinguish missing from known.
Show worked solution
Check >= 20 first and >= 10 second. The original broad branch catches 22 before the narrower condition can be reached; the revised order labels 22 very heavy and 15 heavy.
Check your solution
- 22 becomes very heavy
- 15 remains heavy
6. A measured shipment has zero weight. How does it differ from an unweighed shipment?
Show hint
Trace the stated values through the rule and distinguish missing from known.
Show worked solution
Zero is a known numeric measurement and is standard under the stated classification, whereas NULL is unknown. A separate validation policy may reject zero, but replacing missing values with zero erases that distinction.
Check your solution
- Zero is a known measurement
- NULL means not yet measured
7. The stored measurement is -0.01 kg. Design a distinct reporting outcome.
Show hint
Trace the stated values through the rule and distinguish missing from known.
Show worked solution
Place a negative-weight invalid branch after the NULL check and before normal ranges. The stated value then receives invalid rather than standard, while missing weights remain unknown. Validate the source separately.
Check your solution
- Negative value is invalid
- NULL remains unknown
8. Predict which values 9.99, NULL and 10.01 survive WHERE weight_kg < 10.
Show hint
Trace the stated values through the rule and distinguish missing from known.
Show worked solution
Only 9.99 survives because it makes the predicate true. NULL produces UNKNOWN and 10.01 makes it false; WHERE retains only true results. Include an explicit OR IS NULL if missing rows are also required.
Check your solution
- 9.99 survives
- NULL and 10.01 do not
9. Modify a filter to include missing weights along with weights below ten.
Show hint
Trace the stated values through the rule and distinguish missing from known.
Show worked solution
Use WHERE weight_kg < 10 OR weight_kg IS NULL. The first condition includes known lower weights and the second includes missing values. A value of 10.00 remains excluded under the strict comparison.
Check your solution
- NULL is included
- 10.00 is excluded
10. Explain why weight_kg = NULL never selects a missing shipment in WHERE.
Show hint
Trace the stated values through the rule and distinguish missing from known.
Show worked solution
Equality with NULL produces UNKNOWN, which WHERE filters out. Replace the predicate with weight_kg IS NULL to select the unweighed shipments; use IS NOT NULL to select known values instead.
Check your solution
- Equality returns UNKNOWN
- IS NULL selects missing values
11. A simple CASE uses WHEN NULL for a missing input. Explain the correction.
Show hint
Trace the stated values through the rule and distinguish missing from known.
Show worked solution
Use a searched CASE with WHEN weight_kg IS NULL THEN unknown. A simple CASE compares its input to the WHEN value, and NULL equality is UNKNOWN, so WHEN NULL does not match.
Check your solution
- Use searched CASE
- Avoid NULL equality
12. A CASE contains only WHEN weight_kg >= 10 THEN heavy. Predict its value for 4.
Show hint
Trace the stated values through the rule and distinguish missing from known.
Show worked solution
The condition is false for 4 and there is no ELSE, so the CASE returns NULL. Add an appropriate ELSE only after deciding whether unknown or invalid inputs need explicit branches.
Check your solution
- 4 produces NULL
- ELSE requires an explicit policy
13. A calculation uses COALESCE(weight_kg, 0). What information is lost for NULL?
Show hint
Trace the stated values through the rule and distinguish missing from known.
Show worked solution
The calculation uses zero for the missing input, so its value alone cannot distinguish a missing measurement from a measured zero. Retain a separate IS NULL indicator if consumers need that distinction.
Check your solution
- NULL is replaced by zero
- Keep a missingness indicator
14. Three weights are 12, NULL and 5. Compare COUNT(*) and COUNT(weight_kg).
Show hint
Trace the stated values through the rule and distinguish missing from known.
Show worked solution
COUNT(*) is 3 because all rows count, while COUNT(weight_kg) is 2 because the NULL input is omitted. Their difference is one missing measurement for this one-weight-per-row fixture.
Check your solution
- COUNT(*) equals 3
- COUNT(weight_kg) equals 2
15. For weights 12, NULL and 5, count heavy and unknown shipments separately.
Show hint
Trace the stated values through the rule and distinguish missing from known.
Show worked solution
A conditional SUM for weight >= 10 yields one heavy shipment, and a separate SUM for IS NULL yields one unknown shipment. The remaining known weight is standard under the lab rule.
Check your solution
- Heavy count is 1
- Unknown count is 1
16. An empty shipment filter feeds SUM(CASE ... ELSE 0 END). Predict the sum.
Show hint
Trace the stated values through the rule and distinguish missing from known.
Show worked solution
The result is NULL because there are no input rows on which ELSE can produce zero. Wrap the aggregate in COALESCE if the reporting contract requires zero for an empty input.
Check your solution
- SUM on empty input is NULL
- Outer COALESCE can yield zero
17. Compare threshold predicates > 10 and >= 10 for 9.99, 10.00 and 10.01.
Show hint
Trace the stated values through the rule and distinguish missing from known.
Show worked solution
Both exclude 9.99 and include 10.01. They differ at 10.00: > excludes it and >= includes it. The business rule must specify the boundary before a report chooses one.
Check your solution
- 10.00 distinguishes the predicates
- 9.99 and 10.01 agree
18. A dashboard converts kilograms to grams before comparing with 10. What is wrong?
Show hint
Trace the stated values through the rule and distinguish missing from known.
Show worked solution
A ten-kilogram threshold equals 10000 grams, so comparing the converted values to 10 changes the business rule. Convert both measurement and threshold consistently and label the unit in the report.
Check your solution
- 10 kg equals 10000 g
- Compare quantities in the same unit
19. A historical classification changes after the shipment weight is corrected. Explain a design choice.
Show hint
Trace the stated values through the rule and distinguish missing from known.
Show worked solution
A dynamic report recomputes from the corrected weight and current rule. If an original decision must be preserved, retain the approved input, rule version and decision time under the applicable history policy.
Check your solution
- Dynamic report can change
- Preserved decision needs input and rule version
20. A report has 8 heavy, 4 standard and 2 unknown shipments out of 15. What should be investigated?
Show hint
Trace the stated values through the rule and distinguish missing from known.
Show worked solution
The listed categories sum to 14, leaving one row unaccounted for. Check for an invalid or unmatched category, filters, duplicated rows and NULL handling before declaring the report reconciled.
Check your solution
- Categories total 14
- One of 15 rows is unaccounted for
Key takeaways
- Define thresholds and missing-value meaning before classification.
- CASE branch order and IS NULL make the rule explicit.
- Test exact boundaries and historical reporting needs.
- IS NULL checks missingness; equality with NULL does not.
- The first true CASE branch wins, so overlapping thresholds require deliberate ordering.
- COUNT(*) includes rows whose weight is missing, while COUNT(weight_kg) excludes those values.