|
| 1 | +/* |
| 2 | +Question 3374. First Letter Capitalization II |
| 3 | +Link: https://leetcode.com/problems/first-letter-capitalization-ii/description/?envType=problem-list-v2&envId=database |
| 4 | +
|
| 5 | +Table: user_content |
| 6 | +
|
| 7 | ++-------------+---------+ |
| 8 | +| Column Name | Type | |
| 9 | ++-------------+---------+ |
| 10 | +| content_id | int | |
| 11 | +| content_text| varchar | |
| 12 | ++-------------+---------+ |
| 13 | +content_id is the unique key for this table. |
| 14 | +Each row contains a unique ID and the corresponding text content. |
| 15 | +Write a solution to transform the text in the content_text column by applying the following rules: |
| 16 | +
|
| 17 | +Convert the first letter of each word to uppercase and the remaining letters to lowercase |
| 18 | +Special handling for words containing special characters: |
| 19 | +For words connected with a hyphen -, both parts should be capitalized (e.g., top-rated → Top-Rated) |
| 20 | +All other formatting and spacing should remain unchanged |
| 21 | +Return the result table that includes both the original content_text and the modified text following the above rules. |
| 22 | +*/ |
| 23 | + |
| 24 | +-- The easiest solution :) |
| 25 | + |
| 26 | +SELECT |
| 27 | + content_id, |
| 28 | + content_textAS original_text, |
| 29 | + INITCAP(content_text)AS converted_text |
| 30 | +FROM user_content |