HackerRank/SQL
[HackerRank/SQL] Revising Aggregations - Top Earners
개발자_조이킴
2022. 7. 19. 01:00
Problem. Revising Aggregations - Top Earners
Link.
The Blunder | HackerRank
Query the amount of error in Sam's result, rounded up to the next integer.
www.hackerrank.com
Description.
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.
Key Point.
SELECT,
MAX,
COUNT,
IF,
Comments:
aiengr_talha님과 유사하게
SELECT
MAX(SALARY * MONTHS),
COUNT(IF(SALARY * MONTHS = MAX(SALARY * MONTHS), 1, null))
FROM Employee;
를 사용하려고 했음 (실제로 시도했지만, 원하는 데이터를 얻어올 수 없었음ㅠ)
- pyata_sandeep님의 답변을 참고하여 쿼리를 재작성함
My Answer.
SELECT
MAX(SALARY * MONTHS),
COUNT(IF(SALARY * MONTHS = (SELECT MAX(SALARY * MONTHS) FROM Employee), 1, null))
FROM Employee;
References.