작성
·
27
0
-- genre unnest
select title, genre from `advanced.array_exercises` cross join UNNEST(genres) as genre;
-- actor unnest
select title, actor.actor, actor.character from `advanced.array_exercises` cross join UNNEST(actors) as actor;
-- actor, genre unnest
select title, actor.actor, actor.character, genre from `advanced.array_exercises` cross join UNNEST(actors) as actor cross join UNNEST(genres) as genre;
-- 일자 별 사용자의 이벤트 발생 횟수
select
order_date ,
sum(if(user_id=1, amount, 0)) as user_1,
sum(if(user_id=2, amount, 0)) as user_2,
sum(if(user_id=3, amount, 0)) as user_3
from `advanced.orders`
group by order_date
order by order_date;
-- 사용자 별 일일 이벤트 발생 횟수
select
user_id,
sum(if(order_date='2023-05-01', amount, 0)) as `2023-05-01`,
sum(if(order_date='2023-05-02', amount, 0)) as `2023-05-02`,
sum(if(order_date='2023-05-03', amount, 0)) as `2023-05-03`,
sum(if(order_date='2023-05-04', amount, 0)) as `2023-05-04`,
sum(if(order_date='2023-05-05', amount, 0)) as `2023-05-05`
from `advanced.orders`
group by user_id
order by user_id;
-- 사용자 별 일일 이벤트 발생 여부
select
user_id,
max(if(order_date='2023-05-01', 1, 0)) as `2023-05-01`,
max(if(order_date='2023-05-02', 1, 0)) as `2023-05-02`,
max(if(order_date='2023-05-03', 1, 0)) as `2023-05-03`,
max(if(order_date='2023-05-04', 1, 0)) as `2023-05-04`,
max(if(order_date='2023-05-05', 1, 0)) as `2023-05-05`
from `advanced.orders`
group by user_id
order by user_id;
with data_event_name_with_screen_step as (
with data_event_name_with_screen as (
with base as (select
event_date,
DATETIME(TIMESTAMP_MICROS(event_timestamp), 'Asia/Seoul') as event_time,
event_name,
user_id,
user_pseudo_id,
max(if(event_param.key = 'firebase_screen',event_param.value.string_value , null)) as firebase_screen
from `advanced.app_logs`
cross join unnest(event_params) as event_param
where event_date between '2022-08-01' and '2022-08-18'
group by all
)
select * except(event_name, firebase_screen), concat(event_name, '-', firebase_screen) as event_name_with_screen from base
)
select
COUNT(DISTINCT user_pseudo_id) AS cnt,
event_date,
event_name_with_screen,
(CASE
WHEN event_name_with_screen = "screen_view-welcome" THEN 1
WHEN event_name_with_screen = "screen_view-home" THEN 2
WHEN event_name_with_screen = "screen_view-food_category" THEN 3
WHEN event_name_with_screen = "screen_view-restaurant" THEN 4
WHEN event_name_with_screen = "screen_view-cart" THEN 5
WHEN event_name_with_screen = "click_payment-cart" THEN 6
ELSE NULL END) as step_number
from data_event_name_with_screen
group by all
having step_number is not null
order by event_date
)
-- 이벤트로 pivot
select
event_date,
sum(if(event_name_with_screen='screen_view-welcome', cnt, 0)) as `screen_view-welcome`,
sum(if(event_name_with_screen='screen_view-home', cnt, 0)) as `screen_view-home`,
sum(if(event_name_with_screen='screen_view-food_category', cnt, 0)) as `screen_view-food_category`,
sum(if(event_name_with_screen='screen_view-restaurant', cnt, 0)) as `screen_view-restaurant`,
sum(if(event_name_with_screen='screen_view-cart', cnt, 0)) as `screen_view-cart`,
sum(if(event_name_with_screen='click_payment-cart', cnt, 0)) as `click_payment-cart`
from data_event_name_with_screen_step
group by all
order by event_date
;
이전 부터 쿼리로 퍼널 분석하기 좋은 방법이 없을까 생각을 했었는데 방향성을 알게 되어 좋은 것 같습니다.
답변 1
0
안녕하세요, 인프런 AI 인턴입니다. 권기영님.
BigQuery에서 ARRAY, STRUCT, 및 PIVOT 기능을 활용한 쿼리를 통해 데이터를 분석하는 경험이 풍부해지고, 퍼널 분석의 흐름을 이해하게 되면 데이터 분석 스킬에 크게 기여할 것입니다. 다양한 SQL 문법을 사용하여 데이터를 변환하고 시각화하는 과정을 잘 수행하신 것 같습니다!
아래 유사한 질문 및 답변들을 통해 퍼널 분석 및 PIVOT 관련 추가 학습이 가능하실 수 있습니다:
구글 스프레드시트 사용 시 데이터 로그 설계에 대한 질문
저는 질문자님의 이해를 돕고자 지식공유자님의 기존 답변을 참고하여 유사한 답변 링크를 추천해드리고 있습니다. 현재 베타 기능으로 답변이 만족스럽지 않을 수 있는 점 양해 부탁드립니다. 🙏 추가적으로 궁금한 점이 있으시면, 이어서 질문해 주세요. 곧 지식공유자께서 답변해 주실 것입니다.