최근 글 ✨

SQL

[LeetCode] 97. Rising Temperature

문제Write a solution to find all dates' id with higher temperatures compared to its previous dates (yesterday).Return the result table in any order.The result format is in the following example. 전날보다 온도가 높은 날의 id값을 출력하면 된다. 쿼리 #1SELECT a.id AS IdFROM Weather aJOIN Weather b ON DATEDIFF(a.recordDate, b.recordDate) = 1 AND a.temperature > b.temperature; 쿼리 #2(LAG 활용)SELECT idFROM ( SELECT ..

[LeetCode] 185. Department Top Three Salaries

문제A company's executives are interested in seeing who earns the most money in each of the company's departments. A high earner in a department is an employee who has a salary in the top three unique salaries for that department.Write a solution to find the employees who are high earners in each of the departments.Return the result table in any order.The result format is in the following example...

[LeetCode] 184. Department Highest Salary

문제Write a solution to find employees who have the highest salary in each of the departments.Return the result table in any order.The result format is in the following example. 쿼리SELECT B.NAME AS DEPARTMENT, A.NAME AS EMPLOYEE, A.SALARY AS SALARYFROM EMPLOYEE ALEFT JOIN DEPARTMENT B ON A.DEPARTMENTID = B.IDWHERE (A.DEPARTMENTID, A.SALARY) IN ( SELECT ..

[LeetCode] 182. Duplicate Emails

문제Write a solution to report all the duplicate emails. Note that it's guaranteed that the email field is not NULL.Return the result table in any order.The result format is in the following example. 중복되는 이메일이 있으면 해당 이메일을 출력하도록 해야한다. 쿼리SELECT EMAILFROM PERSONGROUP BY EMAILHAVING COUNT(EMAIL) > 1; 문제 출처https://leetcode.com/problems/duplicate-emails/description/

[LeetCode] 180. Consecutive Numbers

문제Find all numbers that appear at least three times consecutively.Return the result table in any order.The result format is in the following example. 적어도 3번 연속되는 숫자를 출력하면 된다. 출력 쿼리SELECT DISTINCT A.NUM AS ConsecutiveNumsFROM LOGS AJOIN LOGS B ON A.ID + 1 = B.ID AND A.NUM = B.NUMJOIN LOGS C ON A.ID + 2 = C.ID AND A.NUM = C.NUM; SELECT DISTINCT A.NUM AS Consecut..

[LeetCode] 176. Second Highest Salary

문제Write a solution to find the second highest distinct salary from the Employee table. If there is no second highest salary, return null (return None in Pandas). Employee 테이블에서 두번째로 높은 연봉을 출력한다. 만약 없다면 null을 출력한다. 쿼리SELECT MAX(a.salary) AS SecondHighestSalaryFROM ( SELECT salary, DENSE_RANK() OVER (ORDER BY salary DESC) AS r FROM Employee..