SQL 스터디/HackerRank

[해커랭크] MySQL RIGHT 함수 - Higher Than 75 Marks

황금붕어빵 2023. 9. 11. 07:02

 


 

 

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점보다 높은 학생의 이름을 출력하는 쿼리입니다.

 

그리고 정렬 방식이 각 학생의 이름 마지막 세글자를 기준으로 정렬(오름차순)을 합니다.

 

마지막 세글자를 추출하기 위해 RIGHT 함수를 활용하면 됩니다!

select name
from students
where marks > 75
order by right(name,3), id

where 구문에는 점수가 75점 보다 높은 조건을 작성하고 이름의 마지막 세글자는 right(name, 3)으로 작성하면 됩니다.

 

그리고 마지막 세글자 이름이 똑같은 경우에는 id 기준으로 오름차순으로 정렬해줍니다.