/*
1. doesn't want the NAMES of those students who received a grade lower than 8
2. descending order by grade
3. order those particular students by their name alphabetically
4. 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.
*/

select case 
            when g.grade <= 7 then name = Null
            else s.name
        end as name,
       g.grade,
       s.marks
from students as s
     left join grades as g on s.marks between g.min_mark and g.max_mark
order by g.grade desc, name, s.marks

join문에 between을 넣을 수 있다.

 

(문제 출처 - https://www.hackerrank.com/domains/sql)

'섭섭의 공부 > SQL' 카테고리의 다른 글

[HackerRank] Weather Observation Station 5  (0) 2021.12.25
[LeetCode] Consecutive Numbers  (0) 2021.12.24
[LeetCode] Department Highest Salary  (0) 2021.12.24
[HackerRank] Challenges  (0) 2021.12.23
[HackerRank] Top Earners  (0) 2021.12.22

+ Recent posts