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_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
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_id | label | character_count |
|---|---|---|
| 101 | Málaga | 6 |
| 102 | 東京 | 2 |
| 103 | Data | 4 |
| 104 | naïve | 5 |
| 105 | ETL | 3 |
| 106 | résumé | 6 |
| 107 | A | 1 |
| 108 | delta | 5 |
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.