SQL(26)
-
[LeetCode] 1050. Actors and Directors Who Cooperated At Least Three Times
SELECT actor_id, director_id FROM ActorDirector GROUP BY 1, 2 HAVING count(*)>=3 GROUP BY 1, 2로 설정 이 경우 COUNT(*)에 그룹 1,2별로 카운트 됨
2022.06.09 -
[LeetCode] 197. Rising Temperature
내 첫 쿼리 SELECT id FROM (SELECT id ,recorddate ,temperature ,(LAG(temperature) OVER (ORDER BY id)) AS tem2 FROM weather) sub WHERE (temperature-tem2)>0 완성 쿼리 SELECT w.id FROM weather w JOIN weather w1 ON DATEDIFF(w.recordDate,w1.recordDate) = 1 AND w.temperature > w1.temperature 조인 조건 ON에 DATEDIFF 함수 사용 가능
2022.06.09 -
[HackerRank] Weather Observation Station 5
SELECT city, LENGTH(city) FROM station ORDER BY 2 , 1 LIMIT 1 ; SELECT city, LENGTH(city) FROM station ORDER BY 2 DESC , 1 LIMIT 1 ; city의 이름의 길이가 가장 짧은 거, 가장 긴거 추출 쿼리 작성 하나로 작성할 수는 없었을까?
2022.06.08 -
[HackerRank] Weather Observation Station 3
내 쿼리 SELECT DISTINCT city FROM station WHERE MOD(id,2)=0 짝수 구현시 MOD 함수 이용하기
2022.06.07 -
[LeetCode] 178. Rank Scores
내 쿼리 SELECT score ,DENSE_RANK() OVER (ORDER BY score DESC) AS 'rank' FROM scores ORDER BY score DESC - RANK - DENSE_RANK - ROW_NUMBER RANK() OVER ((PARTITION BY ~) ODER BY ~)
2022.06.07 -
[LeetCode] 184. Department Highest Salary
내 쿼리 SELECT d.name AS Department ,e.name AS Employee ,e.salary AS Salary FROM employee AS e INNER JOIN department AS d ON e.departmentid = d.id WHERE (e.departmentid ,e.salary) IN (SELECT departmentid , MAX(salary) FROM employee GROUP BY departmentid ) SQL은 다중 컬럼 인덱싱이 가능하다
2022.06.07