Round a Completion Percentage
Calculate completion_pct as actual_value divided by target_value times 100.
- Numeric functions
- Sorting
Exercise brief
Understand the request
Operations reporting analyst A quality dashboard reports actual-versus-target completion as a percentage with one decimal place.
A quality dashboard reports actual-versus-target completion as a percentage with one decimal place. Calculate completion_pct as actual_value divided by target_value times 100.
Return
- Return record_id, actual_value, target_value, and completion_pct.
- Round completion_pct to one decimal place and order by record_id.
Constraints
- Use ROUND with an explicit decimal precision.
- Preserve fractional division.
Data you will use
Review the relevant tables before deciding how to join, filter, or aggregate them.
function_cases
record_idINTEGERfirst_nameTEXTlast_nameTEXTlabelTEXTemailTEXTbackup_emailTEXTphoneTEXTraw_unitsTEXTraw_quantityTEXTraw_statusTEXTactual_valueREALtarget_valueREALcompleted_unitsREALelapsed_hoursREAL
Hints, when you need them
Open one clue at a time so you still do the reasoning.
Hint 1
Multiply by a decimal value before division to preserve fractions.
Hint 2
ROUND(expression, 1) keeps one digit after the decimal point.
Hint 3
Compute actual_value * 100.0 / target_value inside ROUND.
Verified SQL answer
Attempt the problem first, then compare structure and reasoning—not just syntax.
Reveal solution and explanation
SELECT record_id, actual_value, target_value, ROUND(actual_value * 100.0 / target_value, 1) AS completion_pct FROM function_cases ORDER BY record_id;Why this works
Explicit decimal arithmetic avoids integer truncation and makes the rounding contract visible in the query.
Success check
Every percentage matches the source ratio at one-decimal precision.
Expected result
Use this output to verify values, aliases, ordering, and row count.
| record_id | actual_value | target_value | completion_pct |
|---|---|---|---|
| 101 | 98.4 | 100 | 98.4 |
| 102 | 104 | 100 | 104 |
| 103 | 87.5 | 90 | 97.2 |
| 104 | 80 | 100 | 80 |
| 105 | 100 | 100 | 100 |
| 106 | 95 | 100 | 95 |
| 107 | 110 | 100 | 110 |
| 108 | 90 | 95 | 94.7 |
Learn the concepts behind this answer
Strengthen your understanding with these targeted learning topics:
Continue practicing
Build the next SQL skill
SELECT Statements
Select columns, filter rows, remove duplicates, and order query results.
CASE Statements & Conditional Logic
Build NULL-aware classifications, precedence-safe decisions, flags, scores, and guarded calculations with portable CASE expressions.
Date Operations & Time-Based Analytics
Practice date arithmetic, safe timestamp ranges, calendar bucketing, dense time series, rolling windows, growth, and cohort analysis.
Open the interactive workspace and practice across SQL topics.