문제 URL : https://solvesql.com/problems/estimated-delivery-date/

 

https://solvesql.com/problems/estimated-delivery-date/

 

solvesql.com

 

*문제 저작권으로 인하여 직접 작성한 쿼리문만 첨부

select date(order_purchase_timestamp) as purchase_date,
count(case when order_delivered_customer_date <= order_estimated_delivery_date then order_id end) as success,
count(case when order_delivered_customer_date > order_estimated_delivery_date then order_id end) as fail
from olist_orders_dataset
where purchase_date like '2017-01-%'
group by purchase_date
order by purchase_date

 

CASE WHEN절과 COUNT함수를 함께 사용하여, 특정 경우에 해당하는 행만 집계함

특정 년월에 해당하는 조건 설정을 위해 LIKE절과 와일드카드 사용

(SQLite 기반으로, date 데이터 내 년,월,일 정보를 추출하는 것은 year 등의 메소드가 아니라 strftime 메소드를 사용해야 함)

'Problem Solving' 카테고리의 다른 글

[백준] 2252-줄 세우기  (1) 2025.02.15
[SolveSQL] 쇼핑몰의 일일 매출액과 ARPPU  (0) 2025.02.06
[백준] 1715-카드 정렬하기  (0) 2025.02.05
[백준] 11286-절댓값 힙  (0) 2025.02.05
[백준] 1927-최소 힙  (0) 2025.02.05

+ Recent posts