coding/sql 코딩테스트

페이지에서 스크롤을 내렸을까?

임이레 2024. 8. 15. 15:25

풀이 

with
  view as (
    select
      user_pseudo_id,
      ga_session_id
    from
      ga
    where
      event_name = 'page_view'
      and page_title = '백문이불여일타 SQL 캠프 입문반'
  ),
  scroll as (
    select
      user_pseudo_id,
      ga_session_id
    from
      ga
    where
      event_name = 'scroll'
      and page_title = '백문이불여일타 SQL 캠프 입문반')


select count(DISTINCT t1.user_pseudo_id, t1.ga_session_id) as total
      ,count(DISTINCT t1.user_pseudo_id, t1.ga_session_id) - count(DISTINCT t2.user_pseudo_id, t2.ga_session_id) as pv_no
      ,count(DISTINCT t2.user_pseudo_id, t2.ga_session_id) - count(DISTINCT t3.user_pseudo_id,t3.ga_session_id) as pv_yes_scroll_no
      ,count(DISTINCT t3.user_pseudo_id,t3.ga_session_id) as pv_yes_scroll_yes 
      
from ga t1 left join view t2 on t1.user_pseudo_id = t2.user_pseudo_id and 
                                t1.ga_session_id = t2.ga_session_id
           left join scroll t3 on t2.user_pseudo_id = t3.user_pseudo_id AND
                                  t2.ga_session_id = t3.ga_session_id