본문 바로가기
코딩테스트/SQL

[solvesql][SQLite] 할부는 몇 개월로 해드릴까요

by 포뇨j 2023. 12. 7.

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 추가하여 제출 완료했다.