프로젝트(진행중)/MySQL

HackerRank 공부 3

일말고프로젝트 2023. 3. 6. 16:54

https://www.hackerrank.com/challenges/the-report/problem

 

The Report | HackerRank

Write a query to generate a report containing three columns: Name, Grade and Mark.

www.hackerrank.com

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.

 

문제 핵심

1. case when으로 컬럼 생성하기

2. null값 생성하기

3. join 할 때 컬럼 between a and b가 됨..

 

다른사람 풀이


SELECT 
    (CASE WHEN Marks>70 THEN S.Name ELSE NULL END),
    G.Grade, 
    S.Marks 
FROM Students S 
JOIN Grades G ON S.Marks BETWEEN G.Min_Mark AND G.Max_Mark
ORDER BY 2 DESC,1,3

감탄..