문제
서울숲 일별 평균 대기오염도 데이터셋은 2022년 서울숲 대기오염도 측정소에서 매일 기록한 대기오염 정보를 담고 있습니다.
measurements 테이블의 pm10 컬럼에는 다양한 대기오염도 측정 기준 중에서도 미세먼지(PM10) 농도가 기록되어 있습니다. 이 데이터를 이용하여 당일의 미세먼지 농도보다 바로 다음날의 미세먼지 농도가 더 안좋은 날을 찾아주세요. 결과는 아래 컬럼들을 포함해야 합니다.
* 윈도우 함수 사용하기
* lead는 다음값, lag는 이전값을 가져오는 함수
풀이
with t1 as (select measured_at as today
, lead(measured_at) over (order by measured_at) as next_day
, pm10
, lead(pm10) over (order by measured_at) as next_pm10
from measurements)
select today, next_day, pm10, next_pm10
from t1
where pm10 < next_pm10
-- 당일 미세먼지 농도보다 다음날의 미세먼지 농도가 더 안 좋은 날
'Data > SQL' 카테고리의 다른 글
[프로그래머스] FrontEnd 개발자 찾기 (1) | 2025.01.02 |
---|---|
[Leetcode] 1045. Customers Who Bought All Products (0) | 2024.01.19 |
[Leetcode] 175. Combine Two Tables, 178. Rank Scores, 184. Department Highest Salary (0) | 2024.01.15 |
[Leetcode] 1661. Average Time of Process per Machine (0) | 2024.01.09 |
[Leetcode] 602. Friend Requests II: Who Has the Most Friends (0) | 2024.01.09 |