Basic SQL Functions SQL Topic exerciseEasyVerified answerSQLite + PostgreSQL + MySQL + SQL Server live · 1 guided

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_idINTEGER
  • first_nameTEXT
  • last_nameTEXT
  • labelTEXT
  • emailTEXT
  • backup_emailTEXT
  • phoneTEXT
  • raw_unitsTEXT
  • raw_quantityTEXT
  • raw_statusTEXT
  • actual_valueREAL
  • target_valueREAL
  • completed_unitsREAL
  • elapsed_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_idactual_valuetarget_valuecompletion_pct
10198.410098.4
102104100104
10387.59097.2
1048010080
105100100100
1069510095
107110100110
108909594.7

Learn the concepts behind this answer

Strengthen your understanding with these targeted learning topics:

Continue practicing

SQL Practice Online

Open the interactive workspace and practice across SQL topics.