xinyu04

导航

SQL 1667 Fix Names in a Table

Table: Users

+----------------+---------+
| Column Name    | Type    |
+----------------+---------+
| user_id        | int     |
| name           | varchar |
+----------------+---------+

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.

Write an SQL query 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.

Solution

这里学习的是字符串的操作: \(concat, substring\) 的用法,以及大小写 \(upper,lower\)

点击查看代码
# Write your MySQL query statement below
select user_id, concat(UPPER(substring(name,1,1)), LOWER(substring(name,2))) as name
from Users
ORDER by user_id ASC

posted on 2022-09-13 17:30  Blackzxy  阅读(23)  评论(0编辑  收藏  举报