Learn with Abdou

INTERACTIVE LECTURES

SQL functions & delivery evidence

Guided class activity · apply the ideas from the full SQL lessons.

Preparing for Lab 4 · After practice, try the team challenge.

Opening your saved work…

Sign in to save across devices → · Download your guest work before switching accounts.

Repair integer division before rounding

Step 5 of 7 · Database: North Shore Deliveries

READ & UNDERSTAND

When both operands are integers, SQLite division truncates toward zero. ROUND(7 / 2, 1) rounds an already truncated 3; it cannot recover the missing fraction. Put a real-valued operand into the division first, such as 7 * 1.0 / 2.

A rate needs a named numerator and denominator. A mean number of scans per package is different from the percentage of packages delivered. Neither a decimal place nor an attractive alias establishes the business meaning.

NULLIF(denominator, 0) changes a zero denominator into NULL. This leaves an undefined ratio missing rather than labeling it zero. Explain why the denominator is valid before interpreting the result.

Worked example
SELECT 7 / 2 AS integer_result, ROUND(7 * 1.0 / 2, 1) AS real_result, 7.0 / NULLIF(0, 0) AS undefined_ratio;

The first expression demonstrates truncation; the second preserves the fractional result. A missing ratio communicates an undefined operation, not a successful zero rate.

The fixed denominator is justified only by this snapshot. Recheck SELECT COUNT(*) FROM packages before reusing the calculation with new data.

Your question

The schema shows 40 packages. Return COUNT(*) AS scan_count and ROUND(COUNT(*) * 1.0 / 40, 1) AS mean_scans_per_package from scans.

Explain your evidence

Why is this mean not the percentage delivered? What would have to change if another package were added?

Try a query to unlock the worked-answer discussion.

Loading…
Table & column names only · ↑ ↓ choose · Tab insert · Esc dismiss

CURRENT DATABASE

Quick schema · North Shore Deliveries

Press Esc or click outside to return to your query. PK = primary key · FK = declared foreign key.

This database has no tables yet. Create a table, then reopen the schema to see its columns.

Control Space also opens names. Enter adds a new line. Control or Command Enter runs your query.

Query results

Predict the result, then run your query.

Predict the result, then run your query.

Read-only activity · One statement per run · First 200 rows displayed · Checks compare the complete bounded result, not just this preview.

Explore this query freely in the playground ↗

Check the save status above. Account-saved work is available in My Progress. Explanations are for discussion, not automatically graded. No prerequisite locks.