Growth ๐ŸŒณ/Practice ๐Ÿ’ป

[ํ•ด์ปค๋žญํฌ] Top Earners

์ธ” 2023. 1. 29. 19:12

๐Ÿ“ข ๋ณธ ํฌ์ŠคํŒ…์— ํ™œ์šฉ๋˜๋Š” ๊ธฐ๋ณธ ๋ฌธ์ œ ๋ฐ ์ž๋ฃŒ ์ถœ์ฒ˜๋Š”

       ํ•ด์ปค๋žญํฌ Prepare / https://www.hackerrank.com/dashboard  ์ž„์„ ๋ฐํž™๋‹ˆ๋‹ค.


โ–  ๋ฌธ์ œ

We define an employee's total earnings to be their monthly  salary x months  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 2  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, months is 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

โ–  ํ’€์ด

  ๋ฌธ์ œ ์š”๊ตฌ์‚ฌํ•ญ  

๋ชจ๋“  ๊ทผ๋กœ์ž๋ฅผ ๋Œ€์ƒ์œผ๋กœ ์ „์ฒด ์ตœ๋Œ€ ์ž„๊ธˆ ๊ธˆ์•ก(salary x months ) ๊ณผ     < WHERE์ ˆ ์กฐ๊ฑด (์ง‘๊ณ„ํ•จ์ˆ˜ ์„œ๋ธŒ์ฟผ๋ฆฌ ์‚ฌ์šฉ)

ํ•ด๋‹น ๊ธˆ์•ก์„ ๋ฐ›๋Š” ๊ทผ๋กœ์ž์ˆ˜๋ฅผ ์ถœ๋ ฅ                                                                 < ์ž„๊ธˆ๋ณ„ ๊ทผ๋กœ์ž์ˆ˜ COUNT ํ•จ์ˆ˜ ์‚ฌ์šฉ

SELECT months*salary as earnings,
COUNT(*)
 FROM Employee
 GROUP BY 1
 HAVING earnings = (SELECT max(months*salary) 
                     FROM Employee)