Data/SQL
[SQL] solvesql 코딩테스트 연습7
쿡국
2024. 4. 29. 13:27
문제1. 레스토랑의 일일 매출
출처 : solvesql 연습문제
문제 정보 : 난이도 2 / 정답률 69.23%
https://solvesql.com/problems/daily-revenue/
https://solvesql.com/problems/daily-revenue/
solvesql.com
정답 쿼리
select day, sum(total_bill) as revenue_daily
from tips
group by day
having revenue_daily >=1000
order by revenue_daily desc
문제 해설

문제2. 쇼핑몰의 일일 매출액과 ARPPU
출처 : solvesql 데이터리안 sql캠프 입문반
문제 정보 : 난이도 3 / 정답률 37.09%
https://solvesql.com/problems/daily-arppu/
https://solvesql.com/problems/daily-arppu/
solvesql.com
정답 쿼리
select strftime('%Y-%m-%d', order_purchase_timestamp) as dt,
count(distinct customer_id) as pu, round(sum(payment_value),2) as revenue_daily,
round(sum(payment_value) / count(distinct 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
문제 해설

1. 주요 포인트 1 - select절 집계함수
select strftime('%Y-%m-%d', order_purchase_timestamp) as dt,
count(distinct customer_id) as pu, round(sum(payment_value),2) as revenue_daily,
round(sum(payment_value) / count(distinct customer_id),2) as arppu
각 칼럼 별로 매출 날짜, 결제 고객 수, 해당 날짜 매출액, 결제 고객 1인 당 평균 결제 금액(ARPPU) 값을 원하므로 적절한 집계함수를 입력해준다.
※ ARPPU 란? : Average Revenue Per Paying User의 약자로, 결제 고객 1인 당 평균 결제 금액을 의미한다.