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

[solvesql][SQLite] 쇼핑몰의 일일 매출액과 ARPPU

by 포뇨j 2023. 12. 6.

https://solvesql.com/problems/daily-arppu/

 

https://solvesql.com/problems/daily-arppu/

 

solvesql.com

 

select date(a.order_purchase_timestamp) as dt,
count(distinct a.customer_id) as pu,
round(sum(b.payment_value), 2) as revenue_daily,
round(sum(b.payment_value)/count(distinct a.customer_id), 2) as arppu
from olist_orders_dataset a join olist_order_payments_dataset b
on a.order_id = b.order_id
where dt >= '2018-01-01'
group by dt
order by dt asc

 

  • 2018년 1월 1일 이후 일별 집계 (dt)
  • 결제 고객 수 (pu)
  • 매출액 (revenue_daily)
  • 전체매출액/결제고객수 (arppu)

위와 같이 조건을 정리한 다음 풀었다.

처음에는 round, ceil, floor 함수가 헷갈렸는데 쓰다보니 익숙해졌다는 걸 느꼈다.

 

  • round() - 반올림 함수. 소수점 n째 자리까지 출력할 경우 round(데이터, n) 형식으로 쓰면 된다.
  • ceil() - 올림 함수. 소수점 아래 숫자를 올리고 정수를 출력한다.
  • floor() - 버림 함수. 소수점 아래 숫자를 버리고 정수를 출력한다.