Ketty gives Eve a task to generate a report containing three columns: Name, Grade and Mark. Ketty doesn't want the NAMES of those students who received a grade lower than 8. The report must be in descending order by grade -- i.e. higher grades are entered first. If there is more than one student with the same grade (8-10) assigned to them, order those particular students by their name alphabetically. Finally, if the grade is lower than 8, use "NULL" as their name and list them by their grades in descending order. If there is more than one student with the same grade (1-7) assigned to them, order those particular students by their marks in ascending order.
Write a query to help Eve.
아래의 조건으로 이름과 등급 그리고 점수 조회하기
- 전체적으로 등급 내림차순으로 정렬
- 8등급 이상이면 알파벳순으로 정렬
- 8등급 미만이면 이름 NULL로 표시 + 점수 오름차순으로 정렬
SELECT
IF (G.Grade >= 8, S.Name, NULL),
G.Grade AS GD,
S.Marks
FROM
Students AS S,
Grades AS G
WHERE S.Marks BETWEEN G.Min_Mark AND G.Max_Mark
ORDER BY
GD DESC,
CASE
WHEN GD >= 8 THEN S.Name
WHEN GD < 8 THEN S.Marks
END ASC
'MYSQL 코테 준비' 카테고리의 다른 글
[HacKerRank SQL] SQL Project Planning - MYSQL (0) | 2021.03.09 |
---|---|
[HacKerRank SQL] Ollivander's Inventory - MYSQL (0) | 2021.02.25 |
[HacKerRank SQL] Top Competitors - MYSQL (0) | 2021.02.24 |
[HacKerRank SQL] Asian Population- MYSQL (0) | 2021.02.24 |
[HacKerRank SQL] New Companies- MYSQL (0) | 2021.02.19 |
댓글