문제
내가 작성한 오답
: 2020-01-10일전부터 2020-01-10까지의 id들을 다 포함시켰다
select count(case when status = 'closed' then 1 end )*1.00/ count(acc_id) closed_ratio
from fb_account_status
where (acc_id,status_date) in (select acc_id, max(status_date)
from fb_account_status
where date(status_date) <= '2020-01-10'
group by acc_id);내가 작성한 정답
: 2020-01-10일 당일의 기록만 구하면 된다
MySQL, PostgreSQL
select count(case when status = 'closed' then 1 end )*1.00/ count(acc_id) closed_ratio
from fb_account_status
where date(status_date) = '2020-01-10';Oracle
select count(case when status = 'closed' then 1 end )*1.00/ count(acc_id) closed_ratio
from fb_account_status
where to_char(status_date,'yyyy-mm-dd') = '2020-01-10';Share article