[업무 지식]/MySQL
[upper, lower] Fix Names in a Table
에디터 윤슬
2024. 11. 14. 09:23
링크
https://leetcode.com/problems/fix-names-in-a-table/
문제
Write a solution to fix the names so that only the first character is uppercase and the rest are lowercase.
Return the result table ordered by user_id.
The result format is in the following example.
정답
select user_id,
concat(upper(substr(name, 1, 1)), lower(substr(name, 2, length(name)))) as name
from users
order by user_id
해설
- upper: 문자를 대문자로 변환
- lower: 문자를 소문자로 변환
- substr: 특정 위치에 문자를 추출
- concat: 문자를 결합