이 영역을 누르면 첫 페이지로 이동
쿄코코 블로그의 첫 페이지로 이동

쿄코코

페이지 맨 위로 올라가기

쿄코코

얼레벌레 생활🤯

African Cities, The Report, Top Competitors

  • 2022.11.15 19:57
  • SQL/HackerRank
    반응형

     

    African Cities 📝 ⭐️

    https://www.hackerrank.com/challenges/weather-observation-station-20/problem?isFullScreen=true 

    ➡️ station 테이블 

    • 출력 : lat_n의 중앙값 찾기 ( 소수점 4째자리에서 반올림) 
    • MySQL은 중앙값을 찾을 수 없기 때문에 PERCENT_RANK 함수를 활용하여 0.5인 lat_n 출력 되도록 하기

     

    A median is defined as a number separating the higher half of a data set from the lower half. Query the median of the Northern Latitudes(LAT_N) from STATION and round your answer to  decimal places. 

    Input Format

    The STATION table is described as follows:

    where LAT_N is the northern latitude and LONG_W is the western longitude.

    SELECT ROUND(lat_n,4)
        FROM
            (SELECT lat_n,
            PERCENT_RANK() OVER (ORDER BY lat_n) as percent
            FROM station) AS s
    WHERE s.percent = 0.5

     


     

    The Report 📝 ⭐️

    https://www.hackerrank.com/challenges/the-report/problem?isFullScreen=true 

    ➡️ students,grades 테이블 

    • 출력 : 이름(grade가 8보다 작을 경우 null 출력) , grade, marks 
    • 조건 1️⃣ : grades 테이블과 students 테이블 조인 => min_mark <= mark <= max_mark 가기 
    • 조건 2️⃣ : ORDER BY grade, name, marks 

     

    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
    


    Note

    Print "NULL"  as the name if the grade is less than 8.

    Explanation

    Consider the following table with the grades assigned to the students:

    So, the following students got 8, 9 or 10 grades:

    • Maria (grade 10)
    • Jane (grade 9)
    • Julia (grade 9)
    • Scarlet (grade 8)

     

    SELECT IF(g.grade < 8, NULL, s.name), g.grade, s.marks
    FROM students s
        INNER JOIN grades g ON s.marks BETWEEN g.min_mark AND g.max_mark
    ORDER BY g.grade DESC, s.name, s.marks

     


     

    Top Competitors 📝 ⭐️

    https://www.hackerrank.com/challenges/full-score/problem?isFullScreen=true 

    ➡️ hackers,difficulty,challenges,submissions 테이블 

    • 출력 : full score(만점) 2개 이상 받은 참가자 찾기
    • 만점 기준 : submission 테이블 score = difficulty 테이블 score
    •  hackers,difficulty,challenges,submissions 조인 시킨 후에 hacker_id와 h.name으로 그룹 시킨 후에 hacker_id값이 두개이상인 값 출력하기

    Julia just finished conducting a coding contest, and she needs your help assembling the leaderboard! Write a query to print the respective hacker_id and name of hackers who achieved full scores for more than one challenge. Order your output in descending order by the total number of challenges in which the hacker earned a full score. If more than one hacker received full scores in same number of challenges, then sort them by ascending hacker_id.

    Input Format

    The following tables contain contest data:

    • Hackers: The hacker_id is the id of the hacker, and name is the name of the hacker.
    •  
    • Difficulty: The difficult_level is the level of difficulty of the challenge, and score is the score of the challenge for the difficulty level.
    •  
    • Challenges: The challenge_id is the id of the challenge, the hacker_id is the id of the hacker who created the challenge, and difficulty_level is the level of difficulty of the challenge.
    •  
    • Submissions: The submission_id is the id of the submission, hacker_id is the id of the hacker who made the submission, challenge_id is the id of the challenge that the submission belongs to, and score is the score of the submission.
    •  
     

    Sample Input

    Hackers Table: 

     Difficulty Table: 

     Challenges Table: 

    Submissions Table: 

    Sample Output

    90411 Joe
    

    Explanation

    Hacker 86870 got a score of 30 for challenge 71055 with a difficulty level of 2, so 86870 earned a full score for this challenge.

    Hacker 90411 got a score of 30 for challenge 71055 with a difficulty level of  2, so 90411 earned a full score for this challenge.

    Hacker 90411 got a score of 100 for challenge 66730 with a difficulty level of 6, so 90411 earned a full score for this challenge.

    Only hacker 90411 managed to earn a full score for more than one challenge, so we print the their hacker_id and name as  space-separated values.

     

    SELECT h.hacker_id, h.name
    FROM submissions s
    	INNER JOIN challenges c ON s.challenge_id = c.challenge_id
    	INNER JOIN difficulty d ON c.difficulty_level = d.difficulty_level
    	INNER JOIN hackers h ON s.hacker_id = h.hacker_id
    WHERE s.score = d.score AND c.difficulty_level = d.difficulty_level
    GROUP BY h.hacker_id, H.name
    HAVING COUNT(h.hacker_id) > 1
    ORDER BY COUNT(h.hacker_id) DESC, h.hacker_id

     

     

     

     

    반응형

    'SQL > HackerRank' 카테고리의 다른 글

    SQL Project Planning,Placements,Symmetric Pairs  (0) 2022.12.06
    Ollivander's Inventory, Challenges,Contest Leaderboard  (0) 2022.11.22
    African Cities, Average Population of Each Continent, Weather Observation Station 5, Binary Tree Nodes, New Companies  (0) 2022.10.31
    Weather Observation Station 16,17,18,19 | Population Census  (0) 2022.10.24
    HackerRank - Top Earners,Weather Observation Station 2, 13, 14, 15  (1) 2022.10.03

    댓글

    이 글 공유하기

    • 구독하기

      구독하기

    • 카카오톡

      카카오톡

    • 라인

      라인

    • 트위터

      트위터

    • Facebook

      Facebook

    • 카카오스토리

      카카오스토리

    • 밴드

      밴드

    • 네이버 블로그

      네이버 블로그

    • Pocket

      Pocket

    • Evernote

      Evernote

    다른 글

    • SQL Project Planning,Placements,Symmetric Pairs

      SQL Project Planning,Placements,Symmetric Pairs

      2022.12.06
    • Ollivander's Inventory, Challenges,Contest Leaderboard

      Ollivander's Inventory, Challenges,Contest Leaderboard

      2022.11.22
    • African Cities, Average Population of Each Continent, Weather Observation Station 5, Binary Tree Nodes, New Companies

      African Cities, Average Population of Each Continent, Weather Observation Station 5, Binary Tree Nodes, New Companies

      2022.10.31
    • Weather Observation Station 16,17,18,19 | Population Census

      Weather Observation Station 16,17,18,19 | Population Census

      2022.10.24
    다른 글 더 둘러보기

    정보

    쿄코코 블로그의 첫 페이지로 이동

    쿄코코

    • 쿄코코의 첫 페이지로 이동

    검색

    메뉴

    • 홈

    카테고리

    • 분류 전체보기 (168)
      • Python (24)
        • 😈 99클럽 코테 스터디 4기 TIL (23)
        • 궁금한거 정리 (1)
      • SQL (16)
        • HackerRank (15)
      • [백준] Python,Java로 풀기📖 (71)
        • 정렬(Sorting) (6)
        • 그리디 (5)
        • 문자열 (7)
        • 수학 (3)
        • DFS&BFS (10)
        • 구현 (4)
        • 다이나믹 (17)
        • 이분탐색 (1)
        • 자료구조 (10)
        • 최단거리 (5)
        • 인덱스트리 (0)
      • [프로그래머스]Python,Java로 풀기 (6)
        • Level 1 (4)
        • Level 2 (2)
      • Study Platform📚 (25)
        • (운영체제) - 블로그 및 강의 참고 (0)
        • 김영한👨🏻‍🏫의 스프링 부트와 JPA 실무 완전 .. (5)
        • (알고리즘)- [이코테] 이것이 코딩테스트다 정리 (10)
        • 그림으로 배우는 Http&Network Basic (10)
      • 까먹을까봐 적는 것들 (4)
      • 테스트 보고 난 후..🤔 (0)
      • kt 에이블스쿨 (18)

    최근 글

    인기 글

    댓글

    공지사항

    아카이브

    태그

    • 99클럽
    • 티스토리챌린지
    • 항해99
    • 백준
    • 프로그래머스
    • TiL
    • 오블완
    • 코딩테스트준비

    나의 외부 링크

    정보

    쿄코코의 쿄코코

    쿄코코

    쿄코코

    블로그 구독하기

    • 구독하기
    • RSS 피드

    방문자

    • 전체 방문자
    • 오늘
    • 어제

    티스토리

    • 티스토리 홈
    • 이 블로그 관리하기
    • 글쓰기
    Powered by Tistory / Kakao. © 쿄코코. Designed by Fraccino.

    티스토리툴바