SELECT 
	DATE(event_time) AS day,
	sum(price)  
FROM 
	(select * from `2019_dec` d
	union all
	select * from `2020_jan` j) a
WHERE 
	event_type = 'purchase' 
GROUP BY 1;

스크린샷 2024-12-05 오전 9.17.32.png

→ 2019년 12월 31일에 매출이 급격하게 하락

# 12월 31일 시간대 별 고객수와 총매출

SELECT
	HOUR(event_time),
	count(distinct user_id),
	sum(price) 
FROM
	online_commerce oc 
WHERE 
	event_time between '2019-12-31 00:00:00' and '2019-12-31 23:59:59'
group by
	HOUR(event_time)
order by 
	HOUR(event_time) ;

스크린샷 2024-12-05 오전 9.37.58.png

→ 12월 30일과 비교했을 때, 12월 31일에 전체적으로 고객수와 총매출이 감소한 것을 볼 수 있음

# 12월 31일 시간대별 유형

SELECT
	hour(event_time) 시간,
	count(if(event_type='view',1,NULL)) cnt_view,
	count(if(event_type='cart',1,NULL)) cnt_cart,
	count(if(event_type='remove_from_cart',1,NULL)) cnt_remove,
	count(if(event_type='purchase',1,NULL)) cnt_purchase
FROM 
	`2019_Dec` d 
WHERE
	date(event_time)='2019-12-31'
group by
	hour(event_time)
order by 
	hour(event_time) ;

스크린샷 2024-12-05 오전 10.07.05.png

→ 전체 유형이 전반적으로 12월 31일이 낮게 나왔는데 오전에 12월 31일 구매횟수가 많이 찍혀있음

# 12월 31일 오전 6-8시 사이 상품별 구매횟수

SELECT
	hour(event_time) 시간,
	product_id,
	count(*) 구매횟수 
FROM
	`2019_Dec` d 
where
	hour(event_time) between 6 and 8
	and date(event_time) = '2019-12-31'
	and	event_type ='purchase'
group by
	hour(event_time), product_id
order by
	구매횟수 desc ;

→ 대부분 1회 구매이고 구매횟수 많은게 2회라 특정 상품에서 쿠폰을 뿌린 것 같지는 않음,,

→ 상품이 아니라 오전 6-8시에 어떠한 이벤트가 있었을 수도?