문제 URL : https://solvesql.com/problems/characteristics-of-orders/

 

https://solvesql.com/problems/characteristics-of-orders/

 

solvesql.com

 

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

select region as Region,
count(distinct(case when category = 'Furniture' then order_id end)) as 'Furniture',
count(distinct(case when category = 'Office Supplies' then order_id end)) as 'Office Supplies',
count(distinct(case when category = 'Technology' then order_id end)) as 'Technology'
from records
group by Region
order by Region

 

구하고자 하는 열 별로 각기 다른 조건에 대해 판단하고 카운팅할 때, CASE WHEN절집계함수와 함께 사용하면 풀이 가능

+ Recent posts