๐ข ๋ณธ ํฌ์คํ ์ ํ์ฉ๋๋ ๊ธฐ๋ณธ ๋ฌธ์ ๋ฐ ์๋ฃ ์ถ์ฒ๋
ํด์ปค๋ญํฌ 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)
'Growth ๐ณ > Practice ๐ป' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฆฌํธ์ฝ๋] 196. Delete Duplicate Emails (0) | 2023.01.29 |
---|---|
[ํด์ปค๋ญํฌ] The Report (2) | 2023.01.29 |
[ํด์ปค๋ญํฌ] Weather Observation Station 16 (0) | 2023.01.28 |
[ํ๋ก๊ทธ๋๋จธ์ค] ๋์ฌ ํ์๊ฐ ๋ง์ ์๋์ฐจ๋ค์ ์๋ณ ๋์ฌ ํ์ ๊ตฌํ๊ธฐ (0) | 2023.01.25 |
[ํ๋ก๊ทธ๋๋จธ์ค] ์๋์ฐจ ์ข ๋ฅ๋ณ ํน์ ์ต์ ์ด ํฌํจ๋ ์๋์ฐจ ์ ๊ตฌํ๊ธฐ (0) | 2023.01.15 |