본문 바로가기
PS/SQL

[HackerRank] Higher Than 75 Marks

by 행복한라이언 2024. 4. 8.
728x90
반응형

문제링크

https://www.hackerrank.com/challenges/more-than-75-marks/problem?isFullScreen=true

 

Higher Than 75 Marks | HackerRank

Query the names of students scoring higher than 75 Marks. Sort the output by the LAST three characters of each name.

www.hackerrank.com

 

1. 핵심

  • Name의 마지막 3개의 문자로 정렬하고 그것이 같다면 ID로 정렬 → 문자열 자르기
    • SUBSTRING('문자열', 시작위치[1 base], 길이)
    • RIGHT('문자열', 길이) - 문자열의 오른쪽에서부터 시작
    • LEFT('문자열', 길이) - 문자열의 왼쪽에서부터 시작

2. 코드(MySQL)

select Name
from STUDENTS 
where Marks > 75
order by right(Name, 3) asc,  ID asc;

3. 활용예제

# substring - 정답: Hello
SELECT SUBSTRING('Hello, World!', 1, 5) AS SubstringResult;

# right - 정답: World!
SELECT RIGHT('Hello, World!', 6) AS RightResult;

# left - 정답: Hello
SELECT LEFT('Hello, World!', 5) AS LeftResult;
728x90
반응형