QUIZ
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.
MY ANSWER
SELECT Name
FROM STUDENTS
WHERE MARKS > 75
ORDER BY RIGHT(NAME,3) ASC, ID ASC
POINT
문자를 잘라야하는 경우에는 세가지만 생각하기 ! ORDER BY에서도 쓸 수 있다 :)
- SUBSTRING(문자열, 시작위치, 길이)
- LEFT(문자열, 길이)
- RIGHT(문자열, 길이)
'SQL' 카테고리의 다른 글
[MYSQL] 버리거나(TRUNCATE) 반올림(ROUND) 하거나 (1) | 2023.11.28 |
---|---|
[MYSQL] 값의 형변환을 해주는 CAST 함수 (0) | 2023.10.14 |
리트코드 1204. Last Person to Fit in the Bus (0) | 2023.08.08 |
리트코드(LeetCode) 1341. Movie Rating (1) | 2023.07.20 |
리트코드(LeetCode) 1211. Queries Quality and Percentage (0) | 2023.07.13 |