[Hacker Rank_MySQL]문제 풀이#Higher Than 75 Marks 본문

IT/코테문제

[Hacker Rank_MySQL]문제 풀이#Higher Than 75 Marks

호랑구야 2022. 2. 21. 09:00

 

SQL > Basic Select > Higher Than 75 Marks

 

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

 

Query the Name of any student in STUDENTS who scored higher than 75 Marks. Order your output by the last three characters of each name. If two or more students both have names ending in the same last three characters (i.e.: Bobby, Robby, etc.), secondary sort them by ascending ID.

 

빨간 글씨는 내가 문제를 풀 때 중요하다고 생각한 부분이다.

75점 이상인 학생의 이름을 가져오는데, 이때 정렬 순서가 특이하다. 첫 번째 조건은 이름의 끝 3글자의 오름차순이고 두 번째 조건은 ID의 오름차순이다. 

끝글자르 신경써야 하므로, RIGHT(칼럼, 숫자)를 활용하여, 칼럼값의 오른쪽에서 숫자만큼을 활용하기로 한다.

 

SELECT NAME
FROM STUDENTS
WHERE MARKS > 75
ORDER BY RIGHT(NAME, 3) ASC, ID ASC
반응형
Comments