-
[HackerRank/Basic Select] Higher Than 75 Marks공부/PS ( SQL) 2022. 5. 16. 00:39
https://www.hackerrank.com/challenges/more-than-75-marks/problem
문제
풀이
SELECT Name FROM STUDENTS WHERE Marks > 75 ORDER BY SUBSTR(Name, -3), ID
- Name 문자열의 뒤 3글자를 정렬 기준으로 삼아야 함
- SUBSTR("문자열", '시작 index', '길이') 또는 SUBSTRING("문자열", '시작 index', '길이') 을 사용하여 문자열을 자를 수 있음
- 마지막 파라미터('길이') 생략 시, 끝까지 추출함
- 예시) SUBSTR(Name, -3) : Name의 문자열의 뒤에서 3번째 문자부터 끝까지 추출함
다른 풀이
SELECT Name FROM STUDENTS WHERE Marks > 75 ORDER BY RIGHT(Name, 3), ID
- LEFT("문자열", 길이) : "문자열"의 왼쪽부터 지정 길이만큼의 문자를 추출한다
- RIGHT("문자열", 길이) : "문자열"의 오른쪽부터 지정 길이만큼의 문자를 추출한다
- MID("문자열", 시작 위치, 길이) : "문자열"의 시작 위치부터 지정 길이만큼의 문자를 추출한다
'공부 > PS ( SQL)' 카테고리의 다른 글
[HackerRank/Basic Select] Employee Salaries (0) 2022.05.16 [HackerRank/Basic Select] Employee Names (0) 2022.05.16 [HackerRank/Basic Select] Weather Observation Station 12 (0) 2022.05.16 [HackerRank/Basic Select] Weather Observation Station 11 (0) 2022.05.16 [HackerRank/Basic Select] Weather Observation Station 10 (0) 2022.05.16