HackerRank/SQL
hackerrank Top Earners
챠오위
2021. 1. 17. 16:24

1)
salary * months = earnings
1-1)
SELECT *, salary * months AS earnings
FROM Employee

1-2)
SELECT salary * months AS earnings
FROM Employee
GROUP BY earnings

1-3)
SELECT salary * months AS earnings
FROM Employee
GROUP BY earnings
ORDER BY earnings

1-4)
SELECT salary * months AS earnings
FROM Employee
GROUP BY earnings
ORDER BY earnings DESC

1-5)
SELECT salary * months AS earnings
FROM Employee
GROUP BY earnings
ORDER BY earnings DESC
LIMIT 1;

2) 갯수 출력
COUNT(*)
2-1)
SELECT salary * months AS earnings, COUNT(*)
FROM Employee
GROUP BY earnings
ORDER BY earnings DESC
LIMIT 1;

SUCCESS!