Skip to content

Commit ae9cc1f

Browse files
committed
Solvesql Solution
- SQL
1 parent 2045fdd commit ae9cc1f

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

Solvesql/Solutions/daily-arppu.sql

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
-- @ss.idx: 7
2+
-- @ss.level: 3
3+
-- @ss.title: 쇼핑몰의 일일 매출액과 ARPPU
4+
-- @ss.slug: daily-arppu
5+
-- @ss.category: JOIN/UNION
6+
-- @ss.note:
7+
8+
SELECT DATE_FORMAT(o.order_purchase_timestamp, '%Y-%m-%d') AS dt
9+
, COUNT(DISTINCT customer_id) AS pu
10+
, ROUND(SUM(p.payment_value), 2) AS revenue_daily
11+
, ROUND(SUM(p.payment_value) / COUNT(DISTINCT customer_id), 2) AS arppu
12+
FROM olist_orders_dataset o
13+
JOIN olist_order_payments_dataset p ON o.order_id = p.order_id
14+
WHERE DATE_FORMAT(o.order_purchase_timestamp, '%Y-%m-%d') >= '2018-01-01'
15+
GROUP BY dt
16+
ORDER BY dt;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-- @ss.idx: 8
2+
-- @ss.level: 3
3+
-- @ss.title: 온라인 쇼핑몰의 월 별 매출액 집계
4+
-- @ss.slug: shoppingmall-monthly-summary
5+
-- @ss.category: JOIN/UNION
6+
-- @ss.note: union all
7+
8+
SELECT order_month
9+
, SUM(IF(temp.is_canceled = 0, amount, 0)) AS ordered_amount
10+
, SUM(IF(temp.is_canceled = 1, amount, 0)) AS canceled_amount
11+
, SUM(IF(temp.is_canceled = 0, amount, 0)) + SUM(IF(temp.is_canceled = 1, amount, 0)) AS total_amount
12+
FROM (
13+
SELECT DATE_FORMAT(o.order_date, '%Y-%m') AS order_month
14+
, IF(o.order_id LIKE 'C%', 1, 0) is_canceled
15+
, oi.price * oi.quantity AS amount
16+
FROM orders o
17+
JOIN order_items oi ON o.order_id = oi.order_id
18+
) AS temp
19+
GROUP BY temp.order_month
20+
ORDER BY temp.order_month;

0 commit comments

Comments
 (0)