Try   HackMD

1667. Fix Names in a Table

Fix Names in a Table

透過leetcode 1667Fix Names in a Table來練習

使用table

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

user_id 是該表的主鍵。
此表包含用戶的ID和名稱。
名稱僅由小寫和大寫字符組成。

題目說明:

編寫一個 SQL 查詢來修復名稱,以便只有第一個字符是大寫的,其餘的都是小寫的

返回按 user_id 排序的結果表。

查詢結果格式如下例所示。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

解題:

以下圖解為第一個例題

select 出user_id與處理轉換大小寫
upper:轉大寫
lower:轉小寫

select user_id,upper(substring(name,1,1)) + lower(substring(name,2,9999999)) as name from Users order by user_id

以下圖解為第二個例題(較正確)

select user_id, concat(upper(left(name,1)), lower(right(name, len(name) -1))) as name from Users order by user_id

By. @UEW2WaUHTqSmPOSfnfXrNw