HackerRank-My SQL
Prepare > SQL > Basic Select > Higher Than 75 Marks
stem_sw
2023. 5. 15. 20:55
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로 2차 정렬.
코드
SELECT Name FROM STUDENTS
WHERE Marks > 75
ORDER BY RIGHT(Name, 3) ASC, ID ASC;
두 번째 시도
SELECT NAME FROM STUDENTS
WHERE MARKS > 75
ORDER BY RIGHT(NAME, 3) , ID;
- 똑같네요
노트
ORDER BY 는 콤마(,)로 여러 기준을 입력한다.