[MySQL] 첫 글자만 대문자로

테이블과 결과

Input: 
Users table:
+---------+-------+
| user_id | name  |
+---------+-------+
| 1       | aLice |
| 2       | bOB   |
+---------+-------+
user_id is the primary key for this table.
This table contains the ID and the name of the user. The name consists of only lowercase and uppercase characters.

Output: 
+---------+-------+
| user_id | name  |
+---------+-------+
| 1       | Alice |
| 2       | Bob   |
+---------+-------+

문제

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

SELECT
    u.user_id AS user_id
    ,CONCAT(UPPER(LEFT(u.name, 1)), LOWER(SUBSTRING(u.name, 2))) AS name
FROM Users u
ORDER BY user_id
;

links

social