Growth ๐ŸŒณ/Practice ๐Ÿ’ป

[ํ•ด์ปค๋žญํฌ] The Report

์ธ” 2023. 1. 29. 19:33

๐Ÿ“ข ๋ณธ ํฌ์ŠคํŒ…์— ํ™œ์šฉ๋˜๋Š” ๊ธฐ๋ณธ ๋ฌธ์ œ ๋ฐ ์ž๋ฃŒ ์ถœ์ฒ˜๋Š”

       ํ•ด์ปค๋žญํฌ Prepare / https://www.hackerrank.com/dashboard  ์ž„์„ ๋ฐํž™๋‹ˆ๋‹ค.


โ–  ๋ฌธ์ œ

https://www.hackerrank.com/challenges/the-report/problem?h_r=internal-search 

 

The Report | HackerRank

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

www.hackerrank.com

 

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

โ–  ํ’€์ด

  ๋ฌธ์ œ ์š”๊ตฌ์‚ฌํ•ญ  

Ketty๋Š” 8๋“ฑ๊ธ‰ ์ดํ•˜์˜ ๋“ฑ๊ธ‰์„ ๋ฐ›์€ ํ•™์ƒ์˜ ์ด๋ฆ„์€ ์›ํ•˜์ง€ ์•Š์Œ.๋ฆฌํฌํŠธ๋Š” ๋“ฑ๊ธ‰์ˆœ(๋‚ด๋ฆผ์ฐจ์ˆœ)์œผ๋กœ ์ •๋ ฌ๋˜์–ด์•ผ ํ•˜๊ณ 8-10 ๋“ฑ๊ธ‰ ๋‚ด ๊ฐ™์€ ๋“ฑ๊ธ‰์ด ์žˆ์„ ๊ฒฝ์šฐ ์ด๋ฆ„ ์•ŒํŒŒ๋ฒณ ์ˆœ์œผ๋กœ ์ •๋ ฌํ•  ๊ฒƒ8 ๋“ฑ๊ธ‰ ๋ฏธ๋งŒ์˜ ๋“ฑ๊ธ‰์„ ๋ฐ›์€ ํ•™์ƒ๋“ค์˜ ์ด๋ฆ„์€ Null๊ฐ’์œผ๋กœ ๋Œ€์ฒดํ•˜๊ณ  ๋“ฑ๊ธ‰(๋‚ด๋ฆผ์ฐจ์ˆœ)์œผ๋กœ ์ •๋ ฌํ•  ๊ฒƒ.๋งŒ์•ฝ 1-7 ๋“ฑ๊ธ‰ ๊ตฌ๊ฐ„ ๋‚ด ๋™์ผ ๋“ฑ๊ธ‰์˜ ํ•™์ƒ์ด ์žˆ๋‹ค๋ฉด ๊ทธ๋“ค์˜ marks ์ˆœ(์˜ค๋ฆ„์ฐจ์ˆœ)์œผ๋กœ ์ •๋ ฌํ•  ๊ฒƒ.

SELECT CASE WHEN GA.Grade < 8 THEN NULL ELSE STD.NAME END AS Name
,GA.grade
,STD.Marks
 FROM STUDENTS STD
 JOIN GRADES GA
 ON STD.Marks BETWEEN GA.Min_Mark AND Max_Mark
 
 ORDER BY 2 DESC, 1;