inblog logo
|
stupefyee
    SQL문제풀기

    [SQL 문제 풀이] Fix Names in a Table (테이블의 이름 수정)

    Stupefyee's avatar
    Stupefyee
    Jun 10, 2025
    [SQL 문제 풀이] Fix Names in a Table (테이블의 이름 수정)
    Contents
    내가 작성한 쿼리
    Fix Names in a Table - LeetCode
    Can you solve this real interview question? Fix Names in a Table - Table: Users +----------------+---------+ | Column Name | Type | +----------------+---------+ | user_id | int | | name | varchar | +----------------+---------+ user_id is the primary key (column with unique values) for this table. This table contains the ID and the name of the user. The name consists of only lowercase and uppercase characters.   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.   Example 1: Input: Users table: +---------+-------+ | user_id | name | +---------+-------+ | 1 | aLice | | 2 | bOB | +---------+-------+ Output: +---------+-------+ | user_id | name | +---------+-------+ | 1 | Alice | | 2 | Bob | +---------+-------+
    Fix Names in a Table - LeetCode
    https://leetcode.com/problems/fix-names-in-a-table/description/
    Fix Names in a Table - LeetCode
    notion image
    이름을 고정하는 솔루션을 작성하여 첫 번째 문자만 대문자로 하고 나머지는 소문자로 고정하세요. user_id로 정렬된 결과 테이블을 반환합니다.
     

    내가 작성한 쿼리

    Oracle

    SELECT user_id, UPPER(SUBSTR(name, 1, 1)) || LOWER(SUBSTR(name, 2)) AS name FROM Users ORDER BY user_id

    MySQL

    SELECT user_id, CONCAT(UPPER(SUBSTR(name, 1, 1)), LOWER(SUBSTR(name, 2))) AS name FROM Users ORDER BY user_id

    차이점

    • 문자열 결합 방식의 차이
      • Oracle : || 기호 사용하여 결합
      • MySQL : CONCAT() 함수 사용하여 결합
     
    Share article
    Contents
    내가 작성한 쿼리

    stupefyee

    RSS·Powered by Inblog