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() - 버림 함수. 소수점 아래 숫자를 버리고 정수를 출력한다.
'코딩테스트 > 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] 복수 국적 메달 수상한 선수 찾기 (1) | 2023.12.07 |
[solvesql][SQLite] 지역별 주문의 특징 (2) | 2023.12.06 |