OkBublewrap

Signup Activation Rate 본문

개발/SQL

Signup Activation Rate

옥뽁뽁 2025. 3. 9. 18:35

Signup Activation Rate

문제

1. 계정 활성화율 구하기

2. 소수점 둘째 자리까지 반올림

 

풀이

select
  round(count(case when t.signup_action = 'Confirmed' then e.user_id end) * 1.0
  / count(distinct e.user_id) * 1.0, 2) as confirm_rate
from emails e
  left join texts t on e.email_id = t.email_id

1️⃣ join: email 기준으로 left join

2️⃣ count:Confirmed인 user_id 갯수 세기

3️⃣ count: 총 유저 수 세기

4️⃣ round: 소수점 둘째 자리까지 반올림

 

다른 풀이

SELECT 
  ROUND(COUNT(texts.email_id)::DECIMAL
    /COUNT(DISTINCT emails.email_id),2) AS activation_rate
FROM emails
LEFT JOIN texts
  ON emails.email_id = texts.email_id
  AND texts.signup_action = 'Confirmed';

1️⃣ join: email 기준으로 left join

2️⃣ join: texts 테이블에서 sign_action인 Confiremed인 값만 join

3️⃣ count(text.email_id): Confiremed 된 아이디 갯수

4️⃣ count(distinct emails.email_id): 전체 아이디

'개발 > SQL' 카테고리의 다른 글

Average Review Ratings  (0) 2025.03.10
Supercloud Customer  (0) 2025.03.09
Cities With Completed Trades  (0) 2025.03.09
Duplicate Job Listings  (0) 2025.03.09
Top 5 Artists  (0) 2025.03.08