SQL

HackerRank_SQL_Higher Tan 75 Marks, 문자열 자르기

응엉잉 2023. 1. 5. 14:12

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

 

SELECT name
FROM students
WHERE marks > 75
ORDER BY RIGHT(name, 3), id

SQL 내 문자열 자르기 함수

LEFT(col_name or str, 길이)

RIGHT(col_name or str, 길이)

SUBSTR(col_name or str, 시작위치, 길이)

ex) 20001109

LEFT(20001109, 4) -> 2000

RIGHT(20001109, 4) -> 1109

SUBSTR(20001109,1,4) -> 2000

SUBSTR(20201109,3) -> 001109 (길이가 정해지지 않으면 끝까지 가져옴)