728x90

 

select YEAR, MONTH, PUCHASED_USERS, round(PUCHASED_USERS/tot_cnt,1) PUCHASED_RATIO
from (select year, to_number(month) month, count(1) PUCHASED_USERS
     from (select distinct to_char(b.sales_date, 'yyyy') year, to_char(b.sales_date, 'mm') month, user_id
          from online_sale b
          where exists (select 'x'
                        from user_info q
                        where to_char(q.joined, 'yyyy') = '2021' and q.user_id = b.user_id)) a1
    group by year, month) a2, (select count(1) tot_cnt from user_info where to_char(joined, 'yyyy') = '2021') b2
order by year, month;

 

////

 

select 
to_char(b.sales_date, 'YYYY') as year
, to_number(to_char(b.sales_date, 'MM')) as month
, count(distinct(b.user_id)) as PUCHASED_USERS
, round(count(distinct(b.user_id))/
           (select count(*) from user_info a where to_char(a.joined, 'YYYY') = '2021'), 1) as PUCHASED_RATIO
from user_info a, online_sale b
where a.user_id = b.user_id
and to_char(a.joined, 'YYYY') = '2021'
group by to_char(b.sales_date, 'YYYY'), to_number(to_char(b.sales_date, 'MM'))
order by 1, 2

 

728x90

설정

트랙백

댓글