기존학습자료 29

해커랭크 - 올림/내림/반올림, 절대값/제곱/제곱근

* CEIL - 소수점 첫째 자리에서 올림 * FLOOR - 소수점 첫째 자리에서 내림 * ROUND - 숫자를 각 자리에서 반올림 * TRUNCATE(숫자, 버릴 자릿수) - 숫자를 버릴 자릿수 아래로 버림 * ABS - 절대값 * POWER - 제곱 * SQRT - 양수 x 에 대한 제곱근을 반환 Average Population https://www.hackerrank.com/challenges/average-population/problem SELECT Floor(AVG(population)) FROM CITY Weather Observation Station 2 https://www.hackerrank.com/challenges/weather-observation-station-2/submiss..

해커랭크 - Top earners

Top earners - 서브쿼리 https://www.hackerrank.com/challenges/earnings-of-employees/problem SELECT months*salary as earnings , count(*) FROM employee WHERE months*salary = (SELECT MAX(months*salary) FROM employee) GROUP BY earnings -- Having >>> GROUP BY 결과물을 다시 한 번 필터링 해줄 때 SELECT months*salary AS earnings , count(*) FROM employee GROUP BY earnings HAVING earnings = (SELECT MAX(months*salary) FROM e..

Leetcode 184 - Department Highest Salary

*** 다시 풀어볼 것 184. Department Highest Salary https://leetcode.com/problems/Department-Highest-Salary/ # 각각의 부서에서 누가 가장 고소득자인지 # sel 부서, 직원, 급여 # 순서 상관 x SELECT d.name AS Department , e.name AS Employee , e.salary AS Salary FROM employee as e INNER JOIN ( SELECT departmentID, MAX(salary) AS max_salary FROM Employee GROUP BY departmentID ) AS dh ON e.departmentID = dh.departmentID AND e.salary = dh..

Leetcode 180 - Consecutive Numbers

Consecutive Numbers https://leetcode.com/problems/consecutive-numbers/ # 최소 3번이상 연속적으로 나타나는 숫자 찾기 # 순서는 상관없음 SELECT DISTINCT l.num AS ConsecutiveNums -- 중복제거 FROM logs AS l INNER JOIN logs AS l_next ON l.id + 1 = l_next.id INNER JOIN logs AS l_next2 ON l.id + 2 = l_next2.id # three times consecutively WHERE l.num = l_next.num AND l_next.num = l_next2.num