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

Measure Unicode Labels by Character

Return each record_id, label, and the trimmed label character count.

  • String functions
  • Sorting

Exercise brief

Understand the request

Localization pipeline engineer A label-quality check needs user-visible character counts rather than encoded byte counts.

A label-quality check needs user-visible character counts rather than encoded byte counts. Return each record_id, label, and the trimmed label character count.

Return

  • Alias the count as character_count.
  • Order by record_id ascending.

Constraints

  • Trim edge spaces before measuring.
  • Use the engine function that counts characters, not bytes.

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

MySQL LENGTH measures bytes, so use CHAR_LENGTH for this requirement.

Hint 2

TRIM prevents the padded Data label from reporting six characters.

Hint 3

Use LENGTH or CHAR_LENGTH on TRIM(label), depending on the engine.

Verified SQL answer

Attempt the problem first, then compare structure and reasoning—not just syntax.

Reveal solution and explanation
SELECT record_id, label, LENGTH(TRIM(label)) AS character_count FROM function_cases ORDER BY record_id;

Why this works

Character and byte lengths differ for Unicode text. The explicit engine variants preserve the business meaning of a visible-character limit.

Success check

Multibyte labels and a trailing-space label receive their correct visible character counts.

Expected result

Use this output to verify values, aliases, ordering, and row count.

record_idlabelcharacter_count
101Málaga6
102東京2
103Data 4
104naïve5
105ETL3
106résumé6
107A1
108delta5

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.