일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
- array.slice()
- Where
- node.js
- array.push()
- 재귀함수
- 배열
- 코플릿
- 최강의 인생
- for문
- 개발자_조이킴
- Developer_JoyKim
- JavaScript
- Hackerrank
- 역행자
- 블록체인
- SQL
- join
- 코딩공부
- Programmers
- 알고리즘
- select
- 개발자의 책장
- Algorithms
- MySQL
- 프로그래머스
- 코딩테스트
- 코드스테이츠
- array
- 자바스크립트
- 정규표현식
- Today
- Total
CodingSpace
[HackerRank/SQL] Basic Join - The Report 본문
Problem. Basic Join - The Report
Link.
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
Description.
You are given two tables: Students and Grades. Students contains three columns ID, Name and Marks.
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.
STUDENTS, GRADES 테이블을 사용하여 학생의 이름(NAME), 등급(GRADE), 점수(MARKS)를 조회하시오.
이때 8등급 보다 낮은 등급(1-7)을 가진 학생의 이름은 NULL로 처리하고, 등급이 높은 순으로 정렬하시오.
단 8등급 이상의 학생들의 경우 등급이 같은 경우 이름을 알파벳 순으로 정렬하고,
8등급 미만의 학생들의 경우 등급이 같은 경우 점수가 낮은순으로 정렬하시오.
Key Point.
IF,
JOIN,
BETWEEN,
My Answer.
SELECT
IF(GRADE < 8, NULL, NAME),
G.Grade,
S.Marks
FROM Students S
JOIN Grades G
WHERE S.MARKS BETWEEN G.MIN_MARK AND G.MAX_MARK
ORDER BY GRADE DESC, NAME
References.
'HackerRank > SQL' 카테고리의 다른 글
[HackerRank/SQL] Revising Aggregations - The Count Function (0) | 2022.07.05 |
---|---|
[HackerRank/SQL] Basic SELECT - Employee Salaries (0) | 2022.07.01 |
[HackerRank/SQL] Basic Join - Average Population of Each Continent (0) | 2022.06.08 |
[HackerRank/SQL] Basic Join - Population Census (0) | 2022.05.26 |
[HackerRank/SQL] Advanced Select - The PADS (0) | 2022.05.14 |