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

쿄코코

페이지 맨 위로 올라가기

쿄코코

얼레벌레 생활🤯

HackerRank - Top Earners,Weather Observation Station 2, 13, 14, 15

  • 2022.10.03 23:09
  • SQL/HackerRank
    반응형

     

    Top Earners 📝 ⭐️

    https://www.hackerrank.com/challenges/earnings-of-employees/problem?isFullScreen=true 

    ➡️ employee 테이블 

    • salary * months 의 최댓값과 이 최댓값을 가진 사람 수 구하기
      참고 1) 필드명 alias 할 경우 HAVING은 alias을 사용하여야 한다, GROUP BY 안에는 alias 필드명 사용해도 안사용해도 무관(MYSQL 기준), ORACLE에서는 GROUPBY alias 사용하면 안된다(salary*months) ⭐️

      참고 2) 상위 뽑기 할 때, MYSQL - LIMT 사용, ORACLE - rownum ⭐️
     
     

    We define an employee's total earnings to be their monthly  worked, and the maximum total earnings to be the maximum total earnings for any employee in the Employee table. Write a query to find the maximum total earnings for all employees as well as the total number of employees who have maximum total earnings. Then print these values as  space-separated integers.

    Input Format

    The Employee table containing employee data for a company is described as follows: 

    where employee_id is an employee's ID number, name is their name, monthsis the total number of months they've been working for the company, and salary is the their monthly salary.

    Sample Input

    Sample Output

    69952 1
    

    Explanation

    The table and earnings data is depicted in the following diagram: 

    The maximum earnings value is . The only employee with earnings is Kimberly, so we print the maximum earnings value () and a count of the number of employees who have earned  (which is ) as two space-separated values.

    --MYSQL
    SELECT salary*months as total,COUNT(name) 
    FROM employee 
    GROUP BY (total)
    ORDER BY total DESC
    LIMIT 1;
    
    --ORACLE
    SELECT *
    FROM
    (
        SELECT salary*months as total,COUNT(name) 
        FROM employee 
        GROUP BY (salary*months)
        ORDER BY total DESC
    )
    WHERE rownum<=1;
    SELECT salary*months as total,COUNT(*) 
    FROM employee 
    GROUP BY (total)
    HAVING total = (SELECT MAX(salary*months) FROM employee);

     


     

    Weather Observation Station 2📝 

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

    ➡️ station 테이블 

    • lat_n,long_w의 합을 구하기(단, 소수점 세자리에서 반올림) => SUM,ROUND 함수 이용하기

     

     

    Query the following two values from the STATION table: 

    1. The sum of all values in LAT_N rounded to a scale of decimal places.
    2. The sum of all values in LONG_W rounded to a scale of 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.

    Output Format

    Your results must be in the form:

    lat lon
    

    where  is the sum of all values in LAT_N and  is the sum of all values in LONG_W. Both results must be rounded to a scale of  decimal places.

    SELECT ROUND(SUM(lat_n),2),ROUND(SUM(long_w),2) FROM station;

     


     

    Weather Observation Station 13📝 

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

    ➡️ station 테이블 

    • 38.7880보다 크고 137.2345보다 작은 lat_n의 합 구하기(단, 소수점 5자리에서 버림) => SUM,TRUNCATE 함수 이용 
      참고 ) 버림은 TRUNCATE ⭐️

     

    Query the sum of Northern Latitudes (LAT_N) from STATIONhaving values greater than 38.7880 and less than 137.2345. Truncate your answer to  4 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 TRUNCATE(SUM(lat_n),4)
    FROM station
    WHERE lat_n>38.7880 AND lat_n<137.2345;

     


     

    Weather Observation Station 14📝 

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

    ➡️ station 테이블 

    • 137.2345보다 작은 lat_n의 최댓값 구하기(단, 소수점 5자리에서 버림) => MAX , TRUNCATE 함수 이용 
     

    Query the greatest value of the Northern Latitudes (LAT_N) from STATION that is less than  137.2345. Truncate your answer to 4 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 TRUNCATE(MAX(lat_n),4)
    FROM station
    WHERE lat_n<137.2345;

     


     

    Weather Observation Station 15📝 

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

    ➡️ station 테이블 

    • lat_n이 137.2345보다 작은 값을 큰 순서대로 나열
    • 나열한 것 중에 lat_n이 가장 큰 값의 lat_n 값 구하기( 단, 소수점 다섯번째에서 반올림) 
     

    Query the Western Longitude (LONG_W) for the largest Northern Latitude (LAT_N) in STATION that is less than 137.2345. 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(LONG_W, 4) 
    FROM STATION 
    WHERE LAT_N < 137.2345 
    ORDER BY LAT_N DESC LIMIT 1;
    
    SELECT ROUND(LONG_W, 4) 
    FROM STATION 
    WHERE lat_n = (SELECT MAX(lat_n) FROM station WHERE lat_n<137.2345);

     

    반응형

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

    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
    Revising Aggregations - Averages,Average Population,Japan Population,Population Density Difference,The Blunder  (0) 2022.09.17
    Employee Salaries,Type of Traingle,The PADS,Revising Aggregations - (The Count Function,The Sum Function)  (0) 2022.09.12
    HackerRank- Weather Observation Station 10,11,12,Higher Than 75 Marks,Employee Names  (0) 2022.09.12

    댓글

    이 글 공유하기

    • 구독하기

      구독하기

    • 카카오톡

      카카오톡

    • 라인

      라인

    • 트위터

      트위터

    • Facebook

      Facebook

    • 카카오스토리

      카카오스토리

    • 밴드

      밴드

    • 네이버 블로그

      네이버 블로그

    • Pocket

      Pocket

    • Evernote

      Evernote

    다른 글

    • 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
    • Revising Aggregations - Averages,Average Population,Japan Population,Population Density Difference,The Blunder

      Revising Aggregations - Averages,Average Population,Japan Population,Population Density Difference,The Blunder

      2022.09.17
    • Employee Salaries,Type of Traingle,The PADS,Revising Aggregations - (The Count Function,The Sum Function)

      Employee Salaries,Type of Traingle,The PADS,Revising Aggregations - (The Count Function,The Sum Function)

      2022.09.12
    다른 글 더 둘러보기

    정보

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

    쿄코코

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

    검색

    메뉴

    • 홈

    카테고리

    • 분류 전체보기 (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)

    최근 글

    인기 글

    댓글

    공지사항

    아카이브

    태그

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

    나의 외부 링크

    정보

    쿄코코의 쿄코코

    쿄코코

    쿄코코

    블로그 구독하기

    • 구독하기
    • RSS 피드

    방문자

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

    티스토리

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

    티스토리툴바