본문 바로가기

SQL/[HackerRank]

[HackerRank/MySQL] Top Earners

728x90

< Problem >

가장 높은 연봉과 이에 해당되는 직원 수 구하기

링크:  https://www.hackerrank.com/challenges/earnings-of-employees/problem 

 

Top Earners | HackerRank

Find the maximum amount of money earned by any employee, as well as the number of top earners (people who have earned this amount).

www.hackerrank.com


< Code >

SELECT MAX(salary * months), COUNT(*)
FROM employee
WHERE(salary * months) = (SELECT MAX(salary * months) FROM employee)

 

< Lesson & Learned >

SELECT: 키워드와 함께 검색하고 싶은 속성의 이름을 나열
FROM: 키워드와 함께 검색하고 싶은 속성이 있는 데이블의 이름을 나열
WHERE: 키워드와 함께 비교 연산자(=, <, >=, <>)와 논리 연산자(AND, OR, NOT)를 이용한 검색 조건 제시
MAX( ): 속성 값의 최댓값을 검색하기 위한 집계함수
COUNT( ):  속성 값의 개수를 검색하기 위한 집계함수. NULL 속성 값은 제외하고 계산됨.

728x90