상세 컨텐츠

본문 제목

Higher Than 75 Marks(HackerRank)

SQL/MySQL 문제풀이

by 관재탑 2022. 7. 18. 16:34

본문

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

 

 

문제

Query the Name of any student in STUDENTS who scored higher than  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.

 

 

정답

SELECT Name 
FROM STUDENTS
WHERE Marks > 75
ORDER BY RIGHT(Name,3), ID

 

 

해설

RIGHT(Name, 3)으로 Name 컬럼의 오른쪽 3글자를 기준으로 정렬해준 다음 만약에 글자가 같을 경우에는 추가로 ID컬럼을 기준으로 정렬해준다.

관련글 더보기

댓글 영역