새소식

IT/SQL

[해커랭크] The Report

  • -
728x90
반응형

문제링크 : https://www.hackerrank.com/challenges/the-report/problem?isFullScreen=true

 

You are given two tables: Students and Grades. Students contains three columns ID, Name and Marks.

Grades contains the following data:

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.

Sample Input

Sample Output

Maria 10 99
Jane 9 81
Julia 9 88 
Scarlet 8 78
NULL 7 63
NULL 7 68


Note

Print "NULL"  as the name if the grade is less than 8.

Explanation

Consider the following table with the grades assigned to the students:

So, the following students got 8, 9 or 10 grades:

  • Maria (grade 10)
  • Jane (grade 9)
  • Julia (grade 9)
  • Scarlet (grade 8)

 

🔉 문제 설명

 

8점보다 낮은 학생 제외

등급으로 내림차순으로 작성(등급이 높은 학생부터)

같은 학년을 받은 학생이 두 명 이상인 경우 알파벳순으로 정렬

마지막 등급이 8미만인 경우 "NULL"을 이름으로 사용하고 등급별로 내림차순으로 나열

같은 등급을 가진 학생이 둘 이상인 경우 점수별로 오름차순으로 정

 

SELECT
    CASE
        WHEN g.grade < 8 THEN null
        ELSE s.name
    END AS g,
    g.grade, s.marks
FROM students s join grades g ON s.marks BETWEEN g.min_mark AND g.max_mark
ORDER BY g.grade DESC, s.name, s.marks

 


FROM students s join grades g ON s.marks BETWEEN g.min_mark AND g.max_mark

728x90

'IT > SQL' 카테고리의 다른 글

[해커랭크] Ollivander's Inventory  (0) 2023.04.08
[해커랭크] Top Competitors  (0) 2023.03.31
[해커랭크] Weather Observation Station 20  (0) 2023.03.31
[해커랭크] New Companies  (0) 2023.03.31
[해커랭크] Binary Tree Nodes  (0) 2023.03.31
Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.