https://solvesql.com/problems/installment-month/
https://solvesql.com/problems/installment-month/
solvesql.com
select payment_installments,
count(distinct order_id) as order_count,
min(payment_value) as min_value,
max(payment_value) as max_value,
avg(payment_value) as avg_value
from olist_order_payments_dataset
where payment_type = 'credit_card'
group by payment_installments
min, max, avg 등의 집계함수만 알고있다면 금방 풀 수 있는 문제다.
- min() - 최솟값
- max() - 최댓값
- avg() - 평균값
다만 문제를 꼼꼼히 읽을 필요가 있다.
처음엔 where 절 없이 제출했는데 틀렸다는 결과가 나와서, 다시 읽으니 '신용카드로 주문한 내역'을 구해야 했다.
credit_card 조건을 where 절에 추가한 후 다시 제출했는데 또 틀렸다. order_count가 맞지 않다는 것이다.
distinct 추가하여 제출 완료했다.
'코딩테스트 > SQL' 카테고리의 다른 글
[LeetCode][MySQL] Triangle Judgement (0) | 2023.12.13 |
---|---|
[LeetCode][MySQL] Sales Person (0) | 2023.12.13 |
[solvesql][SQLite] 복수 국적 메달 수상한 선수 찾기 (1) | 2023.12.07 |
[solvesql][SQLite] 지역별 주문의 특징 (2) | 2023.12.06 |
[solvesql][SQLite] 쇼핑몰의 일일 매출액과 ARPPU (1) | 2023.12.06 |