Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- leetcode
- Gaimification
- ABC Analysis
- kaggle
- pandas profiling
- 코딩테스트연습
- eda
- ModelCheckPoint
- Inventory Optimization
- SQL
- forecast
- TensorFlowGPU
- 코딩테스트
- 웨어하우스 보관 최적화
- 당신의 인생이 왜 힘들지 않아야 한다고 생각하십니까
- Product Demand
- 신경쓰기의 기술
- SKU Consolidation
- 딥러닝
- 데이터분석
- MySQL
- MS SQL Server
- 파이썬
- oracle
- HackerRank
- Labor Management System
- ProfileReport
- 피그마인디언
- 프로그래머스
- tensorflow
Archives
- Today
- Total
오늘도 배운다
The Report / HackerRank, SQL, MySQL 본문
문제
You are given two tables: Students and Grades. Students contains three columns ID, Name and Marks.
Grades contains the following data:

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.
제출답안(MySQL)
SELECT
IF(grade<8, NULL, name) as name, grade, marks
FROM
students AS s JOIN grades AS g ON s.marks BETWEEN g.min_mark AND g.max_mark
ORDER BY 2 DESC, 1
문제 바로가기(MySQL)
728x90
'코딩테스트연습(SQL)' 카테고리의 다른 글
| Top Competitors / HackerRank, SQL, MySQL (0) | 2023.01.03 |
|---|---|
| New Companies / HackerRank, SQL, MySQL (0) | 2023.01.03 |
| Average Population of Each Continent / HackerRank, SQL, MySQL (0) | 2022.12.27 |
| Weather Observation Station 20 / HackerRank, SQL, MySQL (0) | 2022.12.27 |
| Weather Observation Station 19 / HackerRank, SQL, MySQL (0) | 2022.12.26 |
Comments