문제 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절을 집계함수와 함께 사용하면 풀이 가능
'Problem Solving' 카테고리의 다른 글
[백준] 11286-절댓값 힙 (0) | 2025.02.05 |
---|---|
[백준] 1927-최소 힙 (0) | 2025.02.05 |
[SolveSQL] 할부는 몇 개월로 해드릴까요 (0) | 2025.02.05 |
[백준] 1515-수 이어 쓰기 (1) | 2025.02.04 |
[SolveSQL] 복수 국적 메달 수상한 선수 찾기 (0) | 2025.02.04 |