Snoopy [리트코드/SQL] 8. Fix Names in a Table (1667)
코딩테스트/리트코드 SQL

[리트코드/SQL] 8. Fix Names in a Table (1667)

Sooyoon Jeong 2022. 12. 8.
 

Delete Duplicate Emails - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview....

leetcode.com


🤔 문제 분석

1) Write an SQL query to fix the names so that only the first character is uppercase and the rest are lowercase.

2) Return the result table ordered by user_id.

 

💡 풀이

SELECT user_id, CONCAT(UPPER(LEFT(name, 1)), LOWER(SUBSTRING(name, 2))) as name
FROM USERS
ORDER BY user_id

 

✍️ check point

문자열 병합: concat

소문자로 변경: lower

대문자로 변경: upper

일부 문자만 추출: left, substring

 

※ oracle에는 첫글자만 대문자로 바꿔주는 inticap 함수가 있는 것 같다.

댓글